package com.douqu.game.main.msg;

import com.alibaba.fastjson.JSONObject;
import com.bean.core.pay.alipay.util.AlipayUtils;
import com.bean.core.pay.tenpay.util.TenpayUtils;
import com.bean.core.util.HttpJsonUtils;
import com.bean.core.util.TimeUtils;
import com.bean.core.util.Utils;
import com.douqu.game.core.config.*;
import com.douqu.game.core.config.card.CardConfig;
import com.douqu.game.core.config.card.CardStarConfig;
import com.douqu.game.core.config.common.GoodsData;
import com.douqu.game.core.config.drop.DropGroupConfig;
import com.douqu.game.core.config.goods.PropConfig;
import com.douqu.game.core.config.mall.MallConfig;
import com.douqu.game.core.config.store.GoblinStoreConfig;
import com.douqu.game.core.controller.PlayerController;
import com.douqu.game.core.e.*;
import com.douqu.game.core.entity.Player;
import com.douqu.game.core.entity.common.TwoTuple;
import com.douqu.game.core.entity.db.CardDB;
import com.douqu.game.core.entity.db.MailDB;
import com.douqu.game.core.entity.ext.BagInfo;
import com.douqu.game.core.entity.ext.BoonInfo;
import com.douqu.game.core.entity.ext.MailInfo;
import com.douqu.game.core.entity.ext.TaskInfo;
import com.douqu.game.core.entity.ext.data.boon.*;
import com.douqu.game.core.entity.ext.data.challenge.ArenaData;
import com.douqu.game.core.entity.ext.data.challenge.BossData;
import com.douqu.game.core.entity.ext.data.challenge.ExpeditionData;
import com.douqu.game.core.entity.ext.data.challenge.OfficialRankData;
import com.douqu.game.core.entity.ext.data.mall.MallData;
import com.douqu.game.core.entity.ext.data.timeLimit.TimePropDB;
import com.douqu.game.core.entity.world.WorldAuctionBean;
import com.douqu.game.core.entity.world.WorldAuctionData;
import com.douqu.game.core.entity.world.WorldRankData;
import com.douqu.game.core.factory.*;
import com.douqu.game.core.protobuf.SGCommonProto;
import com.douqu.game.core.protobuf.SGMainProto;
import com.douqu.game.core.protobuf.SGPlayerProto;
import com.douqu.game.core.util.*;
import com.douqu.game.core.web.AppStoreNotifyParam;
import com.douqu.game.main.GameServer;
import com.douqu.game.main.server.SpringContext;
import com.douqu.game.main.server.StoreManager;
import com.douqu.game.main.server.WorldManager;
import com.douqu.game.main.service.PlayerService;
import com.google.protobuf.InvalidProtocolBufferException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.MessageFormat;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author wangzhenfei
 * 2017-08-21 10:06
 * 福利消息通道（商店，祭坛，拍卖行，酒馆）
 */
@Component
public class BoonMsgChannel implements AMsgChannel {
    @Autowired
    PlayerService playerService;

    @Override
    public void messageChannel(int code, PlayerController playerController, byte[] data) throws Exception {
        //获取相应的数据
        if (playerController == null)
            throw new Exception("playerController is null");
        switch (code) {
            /*****************************充值和福利***********************/
            case SGMainProto.E_MSG_ID.MsgID_Bonus_RechargeInit_VALUE:
                rechargeInit(playerController, code);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Bonus_RechargeCheck_VALUE:
                rechargeCheck(playerController, code, data);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Bonus_RechargeVerify_VALUE:
                rechargeVerify(playerController, code, data);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Bonus_BuyVipGiftBag_VALUE:
                buyVipGiftBag(playerController, code, data);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Bonus_ReceiveMouthCardReward_VALUE:
                receiveMouthCardReward(playerController, code, data);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Bonus_ReceiveFirstRechargeReward_VALUE:
                receiveFirstRechargeReward(playerController, code, data);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Bonus_BonusBoardInit_VALUE:
                bonusBoardInit(playerController, code, data);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Bonus_DailySignReward_VALUE:
                dailySignReward(playerController, code, data);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Bonus_BuyFund_VALUE:
                buyFund(playerController, code, data);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Bonus_ReceiveFundReward_VALUE:
                receiveFundReward(playerController, code, data);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Bonus_LoginTimesRewardInit_VALUE:
                loginTimesRewardInit(playerController, code, data);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Bonus_ReceiveLoginTimesReward_VALUE:
                receiveLoginTimesReward(playerController, code, data);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Bonus_RechargeGuideInit_VALUE:
                rechargeGuideInit(playerController, code, data);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Bonus_GetTimeLimitActivity_VALUE:
                getTimeLimitActivity(playerController, code, data);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Bonus_TimeLimitActivityInit_VALUE:
                timeLimitActivityInit(playerController, code, data);
                break;
            /*****************************地精商店***********************/
            case SGMainProto.E_MSG_ID.MsgID_Store_InitInfo_VALUE:
                storeRefresh(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Store_BuyGoods_VALUE:
                buyGoods(playerController, data, code);
                break;
            /******************************次数购买**********************/
            case SGMainProto.E_MSG_ID.MsgID_Store_BuyTimes_VALUE:
                buyTimes(playerController, data, code);
                break;
            /*****************************祭坛***********************/
            case SGMainProto.E_MSG_ID.MsgID_Altar_Init_VALUE:
                //祭坛信息
                playerController.getPlayer().getAltarData().altarInit(playerController);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Altar_Sacrifice_VALUE:

                SGPlayerProto.C2S_Sacrifice r = SGPlayerProto.C2S_Sacrifice.parseFrom(data);
                if (r == null) {
                    playerController.sendWarn(WordFactory.CURRENT_ALTAR);
                    return;
                }
                playerController.getPlayer().getAltarData().getAltarReward(playerController, r.getId());

                break;
            /*****************************酒馆***********************/
            case SGMainProto.E_MSG_ID.MsgID_Pub_LotteryClick_VALUE:
                try {
                    SGPlayerProto.C2S_LotteryClick c = SGPlayerProto.C2S_LotteryClick.parseFrom(data);
                    if (c == null) {
                        playerController.sendWarn(WordFactory.CARD_NOTHING_ERROR);
                        return;
                    }
                    playerController.getPlayer().getLotteryData().getCommonLottery(playerController, c.getType(), c.getBuyType());
                } catch (InvalidProtocolBufferException e) {
                    e.printStackTrace();
                    LogUtils.error(e.getMessage());
                }
                break;
            case SGMainProto.E_MSG_ID.MsgID_Pub_LotteryInit_VALUE:
                playerController.getPlayer().getLotteryData().initLotteryResponse(playerController);
                break;
            /*************************拍卖行******************************/
            case SGMainProto.E_MSG_ID.MsgID_WorldAuctionInit_VALUE:
                auctionValue(playerController, code);
                break;
            case SGMainProto.E_MSG_ID.MsgID_WorldAuctionBuy_VALUE:
                buyAuction(playerController, code, data);
                break;
            case SGMainProto.E_MSG_ID.MsgID_WorldGetAuctionWeeklyReward_VALUE:
                auctionReward(playerController, code);
                break;
            /*****************************mall 商店***********************/
            case SGMainProto.E_MSG_ID.MSGID_Mall_InitInfo_VALUE:
                initMallStore(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MSGID_Mall_Buy_VALUE:
                buyMallGoods(playerController, data, code);
                break;
            /***************************分享***************************/
            case SGMainProto.E_MSG_ID.MsgID_Bonus_ShareSuccess_VALUE:
                shareSuccess(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MsgID_Bonus_ShareReceive_VALUE:
                shareReceive(playerController, data, code);
                break;
            /******************累计在线奖励**************************/
            case SGMainProto.E_MSG_ID.MSGID_Bonus_OnlineRewardInit_VALUE:
                onlineReward(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MSGID_Bonus_OnlineRewardGet_VALUE:
                initOnlineReceive(playerController, data, code);
                break;
            //**************开服活动********************//
            case SGMainProto.E_MSG_ID.MSGID_Bonus_sevenRewardGet_VALUE:
                sevenDayReward(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MSGID_Bonus_sevenRewardInit_VALUE:
                initSevenDayReceive(playerController, data, code);
                break;
            case SGMainProto.E_MSG_ID.MSGID_Bonus_sevenRewardTop_VALUE:
                getMyTopRank(playerController, data, code);
                break;

            default:
                break;
        }
    }

    /**
     * 获得我的嘉联华排名信息
     * @param playerController
     * @param data
     * @param code
     */
    private void getMyTopRank(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_SevenRewardTop request= null;
        try {
            request = SGPlayerProto.C2S_SevenRewardTop.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        SGPlayerProto.S2C_SevenRewardTop.Builder response = SGPlayerProto.S2C_SevenRewardTop.newBuilder();
        WorldRankData worldRankData = WorldInfoFactory.getInstance().getWorldRankData();
        int playerTop= worldRankData.getRankByPlayer(playerController.getPlayer(), request.getType());
        response.setRank(playerTop);
        LogUtils.debug("返回给客户端排名信息：" + response.toString());
        playerController.sendMsg(code, response.build().toByteArray());

    }

    /**
     * 领取开服7日相关礼包
     * @param playerController
     * @param data
     * @param code
     */
    private void sevenDayReward(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_SevenRewardGet request= null;
        try {
            request = SGPlayerProto.C2S_SevenRewardGet.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        int id = request.getId();
        int type =request.getType();
        SevenDayData sevenDayData = playerController.getPlayer().getSevenDayData();
        SGPlayerProto.S2C_SevenRewardGet.Builder response = SGPlayerProto.S2C_SevenRewardGet.newBuilder();

        if (type == E_SevenDayGiftType.SEVEN_DAY_GIFT.getCode()){
            response.setResult(sevenDayData.getAllReward(id));
        }
        else if (type == E_SevenDayGiftType.ACTIVITIES_GIFT.getCode()){
            response.setResult(sevenDayData.getSevenActivities(id));
        }
        LogUtils.debug("返回给客户端奖励领取信息：" + response.toString());
        playerController.sendMsg(code, response.build().toByteArray());
    }

    /**
     * 开服礼包信息
     * @param playerController
     * @param data
     * @param code
     */
    private void initSevenDayReceive(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_SevenRewardInit request= null;
        try {
            request = SGPlayerProto.C2S_SevenRewardInit.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        SGPlayerProto.S2C_SevenRewardInit.Builder response = SGPlayerProto.S2C_SevenRewardInit.newBuilder();
        int type = request.getType();
        if (type == E_SevenDayActiType.SEVEN_DAY_REWARD.getCode()) {

            SevenDayData sevenDayData = playerController.getPlayer().getSevenDayData();
            response.setRewardCurrency(sevenDayData.getIntegral());
            //WorldInfoFactory worldInfoFactory = WorldInfoFactory.getInstance();
            //response.setBuyGiftCount(worldInfoFactory.getBonusCount());
            response.addAllGetActiviesRecords(sevenDayData.getActivitiesList());
            sevenDayData.getRewardList(type).forEach(response::addGetSevenRecords);
            response.setCurrentDay(sevenDayData.getCurrentDays() + 1);
            LogUtils.debug("返回给客户端7天奖励信息：" + response.toString());
            playerController.sendMsg(code, response.build().toByteArray());
        }
        else if (type == E_SevenDayActiType.ACTIVITIES_TOP_REWARD.getCode()){
            SevenDayData sevenDayData = playerController.getPlayer().getSevenDayData();
            sevenDayData.getRewardList(type).forEach(response::addGetSevenRecords);
            response.setCurrentDay(sevenDayData.getCurrentDays()+1);
            LogUtils.debug("返回给客户端嘉联华信息：" + response.toString());
            playerController.sendMsg(code, response.build().toByteArray());
        }
        else {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
        }
    }

    /**
     * 初始化在线奖励
     * @param playerController
     * @param data
     * @param code
     */
    private void onlineReward(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.S2C_OnlineRewardInit.Builder response = SGPlayerProto.S2C_OnlineRewardInit.newBuilder();

        OnlineRewardData onlineRewardData = playerController.getPlayer().getOnlineData();
        response.setOnLineTime((int) (onlineRewardData.getAllOnlineTime()/1000));
        response.addAllGetRecords(onlineRewardData.getOnlineRewardList());

        LogUtils.debug("返回给客户端初始化在线奖励信息：" + response.toString());
        playerController.sendMsg(code, response.build().toByteArray());

    }

    /**
     * 领取在线奖励
     * @param playerController
     * @param data
     * @param code
     */
    private void initOnlineReceive(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_OnlineRewardGet request= null;
        try {
            request = SGPlayerProto.C2S_OnlineRewardGet.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        int id =request.getOnLineId();
        OnlineRewardData onlineRewardData = playerController.getPlayer().getOnlineData();
        boolean isSuc=onlineRewardData.setOnlineReWardState(id);
        SGPlayerProto.S2C_OnlineRewardGet.Builder response = SGPlayerProto.S2C_OnlineRewardGet.newBuilder();

        //领取成功
        if (isSuc){
            response.setResult(true);
            //获得奖励
            BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
            //奖励入包
            OnlineRewardConfig config =DataFactory.getInstance().getGameObject(DataFactory.ONLINE_REWARD,id);
            bagInfo.addGoods(config.reward);
        }else {
            response.setResult(false);
        }
        response.setOnLineId(id);
        response.setOnLineTime((int) (onlineRewardData.getAllOnlineTime()/1000));
        LogUtils.debug("返回给客户端在线奖励领取信息：" + response.toString());
        playerController.sendMsg(code, response.build().toByteArray());
    }


    /**
     * 限时活动初始化
     *
     * @param playerController
     * @param code
     * @param data
     */
    private void timeLimitActivityInit(PlayerController playerController, int code, byte[] data) {
        SGPlayerProto.C2S_TimeLimitActivityInit request = null;
        try {
            request = SGPlayerProto.C2S_TimeLimitActivityInit.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }


        SGPlayerProto.S2C_TimeLimitActivityInit.Builder response = SGPlayerProto.S2C_TimeLimitActivityInit.newBuilder();

        response.setCurrentServerTime(DataFactory.currentTime);
        response.setNextDayOffsetTime(CoreUtils.getNextDayStartOffsetMills(DataFactory.currentTime));
        //限时活动
        List<TimeLimitedActivitiesConfig> configs = DataFactory.getInstance().getDataList(DataFactory.TIME_LIMIT_ACTIVITY_KEY);
        for (TimeLimitedActivitiesConfig config : configs) {
            if (config.isTimeInForReceiver() && config.isServerIn(WorldInfoFactory.getInstance().getServerId()) &&
                    config.isPlatformIn(CoreUtils.formRuleId(playerController.getServerRuleId())[2])) {
                SGCommonProto.KeyListObject.Builder object = SGCommonProto.KeyListObject.newBuilder();
                object.setKey(config.id);
                if (playerController.getPlayer().getBonusData().getActivityRecord().get(config.id) != null) {
                    object.addAllList(playerController.getPlayer().getBonusData().getActivityRecord().get(config.id).getRecordList());
                }
                if (config.type == E_TimeLimitActivityType.TOTAL_RECHARGE.getCode()) {
                    object.setValue(playerController.getPlayer().getRechargeData().getRechargeCount(E_QueryRechargeCountType.DEFINE.getCode()));
                } else if (config.type == E_TimeLimitActivityType.TOTAL_DIAMONDS.getCode()) {
                    object.setValue(playerController.getPlayer().getBonusData().getDiamondsCacheDefine());
                }
                response.addTimeLimitActivity(object.build());
            }
        }
        LogUtils.debug("返回给客户端限时活动初始化信息：" + response.toString());
        playerController.sendMsg(code, response.build().toByteArray());

    }

    /**
     * @param playerController
     * @param code
     * @param data
     */
    private void getTimeLimitActivity(PlayerController playerController, int code, byte[] data) {
        SGPlayerProto.C2S_GetTimeLimitActivity request = null;
        try {
            request = SGPlayerProto.C2S_GetTimeLimitActivity.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        int activityId = request.getActivityId();
        int intValue = request.getIntValue();
        LogUtils.debug("限时活动领取参数：" + request.toString());

        TimeLimitedActivitiesConfig config = DataFactory.getInstance().getGameObject(DataFactory.TIME_LIMIT_ACTIVITY_KEY, activityId);
        if (config == null) {
            LogUtils.error("限时活动配置找不到：" + activityId);
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        if (!config.isTimeInForReceiver()) {
            LogUtils.error("限时活动不在时间范围内");
            playerController.sendWarn(WordFactory.ACTIVITY_TIMEOUT);
            return;
        }
        if (!config.isServerIn(WorldInfoFactory.getInstance().getServerId())) {
            LogUtils.error("限时活动该服务器不在活动内");
            playerController.sendWarn(WordFactory.SERVER_OUTSIDE_ACTIVITY);
            return;
        }
        if (!config.isPlatformIn(CoreUtils.formRuleId(playerController.getServerRuleId())[2])) {
            LogUtils.error("限时活动该渠道平台不在活动内");
            playerController.sendWarn(WordFactory.PLATFOTM_OUTSIDE_ACTIVITY);
            return;
        }

        BonusData bonusData = playerController.getPlayer().getBonusData();
        if (bonusData.hasReceiveActivityReward(config.id, intValue)) {
            LogUtils.error("活动奖励已经领取过了");
            playerController.sendWarn(WordFactory.ACTIVITY_CAMP_GET_REWARD_ED);
            return;
        }
        if (config.type == E_TimeLimitActivityType.TOTAL_RECHARGE.getCode()) {
            int rechargeCount = playerController.getPlayer().getRechargeData().getRechargeCount(E_QueryRechargeCountType.DEFINE.getCode());
            if (rechargeCount < intValue) {
                LogUtils.debug("充值数量不足, 当前" + rechargeCount + ",   需要：" + intValue);
                playerController.sendWarn(WordFactory.RECHARGE_NOT_ENOUGH);
                return;
            }
        } else if (config.type == E_TimeLimitActivityType.TOTAL_DIAMONDS.getCode()) {
            int diamondsCount = playerController.getPlayer().getBonusData().getDiamondsCacheDefine();
            if (diamondsCount < intValue) {
                LogUtils.debug("钻石消耗数量不足, 当前" + diamondsCount + ",   需要：" + intValue);
                playerController.sendWarn(WordFactory.CONSUME_DIAMONDS_NOT_ENOUGH);
                return;
            }

        } else {
            LogUtils.error("暂无此类型限时活动开启 ：" + activityId);
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        GoodsData[] reward = config.reward;
        List<GoodsData> temp = new ArrayList<>();
        for (GoodsData goodsData : reward) {
            if (intValue == goodsData.extraValue[0]) {
                temp.add(goodsData.copy());
            }
        }
        if (temp.size() == 0) {
            LogUtils.error("限时活动对应value找不到 config.id：" + config.id + " intValue :" + intValue);
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        reward = new GoodsData[temp.size()];
        for (int i = 0; i < temp.size(); i++) {
            reward[i] = temp.get(i);
        }

        playerController.getPlayer().getBagInfo().addGoods(reward, null);
        bonusData.addActivityReward(config.id, intValue);
        playerController.sendMsg(code, SGPlayerProto.S2C_GetTimeLimitActivity.newBuilder().setActivityId(activityId).
                setIntValue(intValue).build().toByteArray());
    }

    /**
     * 充值攻略检测
     *
     * @param playerController
     * @param code
     * @param data
     */
    private void rechargeGuideInit(PlayerController playerController, int code, byte[] data) {
        SGPlayerProto.S2C_RechargeGuideInit.Builder response = SGPlayerProto.S2C_RechargeGuideInit.newBuilder();
        response.setVipLv(playerController.getPlayer().getVipLevel());
        response.setVipExp(playerController.getPlayer().getVipExp());
        response.setDailyRechargeRmb(playerController.getPlayer().getRechargeData().getRechargeCount(E_QueryRechargeCountType.DAILY.getCode()));
//
        RechargeConfig rechargeConfig = null;
        for(Map.Entry<Integer, RechargeRecordData.MouthCardRecord> entry : playerController.getPlayer().getRechargeData().getRechargeRecordMap().entrySet())
        {
            rechargeConfig = DataFactory.getInstance().getGameObject(DataFactory.RECHARGE_KEY, entry.getKey());
            if (rechargeConfig.type == E_RechargeGoodsType.MOUTH_CARD.getCode() || rechargeConfig.type == E_RechargeGoodsType.WEEK_CARD.getCode()) {
                //获取月卡剩余天数
                long endTime = entry.getValue().getEndTime();
                if (DataFactory.currentTime <= endTime) {
                    //获取剩余天数
                    int day = CoreUtils.getBetweenDay(DataFactory.currentTime, endTime);
                    if (day != 0) {
                        response.addMouthCards(SGCommonProto.MouthCard.newBuilder().
                                setId(entry.getKey()).
                                setEndDays(day).
                                setHasRewardToday(playerController.getPlayer().getRechargeData().isMouthCardRewardToday(entry.getKey())).
                                build());
                    }
                }
            }
        }

        response.setIsFirstRechargeRecive(playerController.getPlayer().getBonusData().isFistRechargeReceive());
        response.addAllPage(RechargeGuideUtils.getGuideRecharge(playerController.getPlayer()));
        LogUtils.debug("充值攻略返回：" + response.toString());
        playerController.sendMsg(code, response.build().toByteArray());
    }

    /**
     * 充值检测
     *
     * @param playerController
     * @param code
     * @param data
     */
    private void rechargeCheck(PlayerController playerController, int code, byte[] data) {
        SGPlayerProto.C2S_RechargeCheck request = null;
        try {
            request = SGPlayerProto.C2S_RechargeCheck.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        //优惠券id 动态且唯一,苹果支付的时候，这个值是订单号
        String timePropId = request.getTimePropUniqueId();
        //客户端自定义参数
        String clientParam = request.getParam();
        LogUtils.warn(playerController.getName() + " -> 客户端充值参数:" + request.toString());
        SGCommonProto.E_RECHARGE_TYPE rechargeType = request.getRechargeType();
        if (rechargeType == null || rechargeType == SGCommonProto.E_RECHARGE_TYPE.RECHARGE_TYPE_UNKNOW) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        //充值id
        int rechargeId = request.getRecharId();

        TimePropDB timeProp = null;
        LogUtils.debug("充值id：" + rechargeId);
        RechargeConfig rechargeConfig = DataFactory.getInstance().getGameObject(DataFactory.RECHARGE_KEY, rechargeId);
        if (rechargeConfig == null) {
            LogUtils.error("充值id找不到..." + rechargeId);
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }


        clientParam = StringUtils.isNullOrEmpty(clientParam) ? ConstantFactory.PLACEHOLDER : clientParam;

        if (rechargeConfig.type == E_RechargeGoodsType.OPEN_FUND.getCode()) {
            BonusData bonusData = playerController.getPlayer().getBonusData();
            if (bonusData.isFundBuy(SGCommonProto.E_FUND_TYPE.FUND_TYPE_OPEN)) {
                LogUtils.error("开服基金已经购买过");
                playerController.sendWarn(WordFactory.FUND_HAS_BUY);
                return;
            }

            StableDataConfig stableDataConfig = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY, E_StableDataType.OPEN_FUND_PRICE.getCode());
            if (playerController.getPlayer().getVipLevel() < stableDataConfig.intValue) {
                LogUtils.error("vip等级不足 需要：" + stableDataConfig.intValue + ", 当前vip等级：" + playerController.getPlayer().getVipLevel());
                playerController.sendWarn(WordFactory.VIP_LEVEL_NOT_ENOUGH, stableDataConfig.intValue);
                return;
            }
        } else if (rechargeConfig.type == E_RechargeGoodsType.DAILY_GIFT.getCode()) {
            StableDataConfig stableDataConfig = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY, E_StableDataType.DAILY_RECHARGE_GIFT.getCode());
            if (playerController.getPlayer().getVipLevel() < stableDataConfig.intValue) {
                LogUtils.error("vip等级不足 需要：" + stableDataConfig.intValue + ", 当前vip等级：" + playerController.getPlayer().getVipLevel());
                playerController.sendWarn(WordFactory.VIP_LEVEL_NOT_ENOUGH, stableDataConfig.intValue);
                return;
            }

            RechargeRecordData recordData = playerController.getPlayer().getRechargeRecordData();
            if (recordData.isDailyGiftRecordHasBuy(rechargeId)) {
                LogUtils.error("每日礼包已经购买了");
                playerController.sendWarn(WordFactory.DAILY_RECHARGE_GIFT_HAS_BUY);
                return;
            }
        } else if (rechargeConfig.type == E_RechargeGoodsType.DIAMOND.getCode()) {
            if (!StringUtils.isNullOrEmpty(timePropId)) {
                timeProp = playerController.getPlayer().getBagInfo().getTimePropData().getTimeProp(timePropId);
                if (timeProp == null) {
                    LogUtils.error("优惠卷不存在:" + timePropId);
                    playerController.sendWarn(WordFactory.COUPON_UN_EXIST);
                    return;
                }
                if (!timeProp.isTimeIn()) {
                    LogUtils.error("优惠卷已过期:" + timePropId);
                    playerController.sendWarn(WordFactory.COUPON_EXPIRED);
                    return;
                }
                if (timeProp.isUse) {
                    LogUtils.error("优惠卷已被使用:" + timePropId);
                    playerController.sendWarn(WordFactory.COUPON_HAS_USE);
                    return;
                }

                if (rechargeConfig.rmb * 10 < timeProp.getConfig().timePropData.type) {
                    LogUtils.error("充值钻石不够，不能使用优惠券");
                    playerController.sendWarn(WordFactory.COUPON_UN_MATCH_CONDITION);
                    return;
                }
            }
        } else if (rechargeConfig.type == E_RechargeGoodsType.FLASH_SALE.getCode()) {
            if (!playerController.getPlayer().getBonusData().isInTime(rechargeConfig.linkId)) {
                LogUtils.error("限时促销充值不在时间内或者不存在");
                playerController.sendWarn(WordFactory.PARAM_ERROR);
                return;
            }
        }else if (rechargeConfig.type ==E_RechargeGoodsType.OPEN_SERVER_BOON.getCode()){
            //todo 检测是否已购买
//            if (playerController.getPlayer().getSevenDayData.isBuyWelfareGift()){
//                LogUtils.error("已购买过开服红利");
//                playerController.sendWarn(WordFactory.PARAM_ERROR);
//            }
        }

        SGPlayerProto.S2C_RechargeCheck.Builder response = SGPlayerProto.S2C_RechargeCheck.newBuilder();
        response.setIsOk(true);
        response.setRecharId(rechargeId);
        response.setRechargeType(rechargeType);

        String account = !Utils.isNullOrEmpty(playerController.getPlayer().getAccount()) ? playerController.getPlayer().getAccount() : playerController.getPlayer().getDeviceId();
        if (rechargeType != SGCommonProto.E_RECHARGE_TYPE.RECHARGE_TYPE_APPSTORE){
            if(CoreUtils.isRechargeTestAccount(account) || GameServer.getInstance().getWorldManager().isWhite(account) || SpringContext.isDev())
                response.setRmb(100);//测试账号和白名单账号是1分
            else
                response.setRmb(rechargeConfig.rmb * 100);//转换为分
        }else
            response.setRmb(rechargeConfig.rmb * 100);//转换为分


        int diamond = rechargeConfig.getDiamond();
        String platform = rechargeType.name();
        String outTradeNo = PayUtils.createOutTradeNo(platform.substring(platform.lastIndexOf("_")+1));
        String rechargeParam = PayUtils.createRechargeParam(playerController.getObjectIndex(), rechargeId, GameServer.getInstance().getServerId(), playerController.getPlayer().getLv(), diamond, playerController.getServerRuleId(), timeProp, clientParam, outTradeNo);
        LogUtils.info("outTradeNo:", outTradeNo, ", rechargeParam:", rechargeParam);
        response.setOutTradeNo(outTradeNo);
        response.setRechargeParam(rechargeParam);
//        if (rechargeType == SGCommonProto.E_RECHARGE_TYPE.RECHARGE_TYPE_YJ) {
//            //易接是分
//            response.setRechargeParam(rechargeParam);
//        } else if (rechargeType == SGCommonProto.E_RECHARGE_TYPE.RECHARGE_TYPE_ALI) {
//            //支付宝是元
//            String param = null;
//            try {
//                String msg = Utils.isNullOrEmpty(rechargeConfig.name) ? E_RechargeGoodsType.forNumber(rechargeType.getNumber()).getMsg() : rechargeConfig.name;
//                param = AlipayUtils.getSignature(outTradeNo, (response.getRmb() * 1.0f / 100) + "", msg, msg, rechargeParam);
//            } catch (Exception e) {
//                LogUtils.error("支付宝签名错误,参数 -> " + rechargeParam);
//                LogUtils.errorException(e);
//                playerController.sendWarn(WordFactory.PARAM_ERROR);
//                return;
//            }
//            if(Utils.isNullOrEmpty(param))
//            {
//                LogUtils.error("支付宝签名错误,参数 -> " + rechargeParam);
//                playerController.sendWarn(WordFactory.PARAM_ERROR);
//                return;
//            }
//            response.setRechargeParam(param);
//        } else if (rechargeType == SGCommonProto.E_RECHARGE_TYPE.RECHARGE_TYPE_WECHAT) {
//
//
//            //微信是分
//            String param = null;
//            try {
//                String msg = Utils.isNullOrEmpty(rechargeConfig.name) ? E_RechargeGoodsType.forNumber(rechargeType.getNumber()).getMsg() : rechargeConfig.name;
//                param = TenpayUtils.getSignature(outTradeNo, response.getRmb(), msg, msg, rechargeParam, null, null);
//            } catch (Exception e) {
//                LogUtils.errorException(e);
//                LogUtils.error("微信支付签名错误,参数 -> " + rechargeParam);
//                playerController.sendWarn(WordFactory.PARAM_ERROR);
//                return;
//            }
//            if(Utils.isNullOrEmpty(param))
//            {
//                LogUtils.error("微信支付签名错误,参数 -> " + rechargeParam);
//                playerController.sendWarn(WordFactory.PARAM_ERROR);
//                return;
//            }
//            response.setRechargeParam(param);
//        } else if(rechargeType == SGCommonProto.E_RECHARGE_TYPE.RECHARGE_TYPE_APPSTORE) {
//
//            int platformNumber = CoreUtils.getPlatformNumber(playerController.getServerRuleId());
//            if (platformNumber == SGCommonProto.E_PLATFORM_TYPE.PLATFORM_TYPE_APPLE_QIANGWAN_VALUE)
//            {
//                //抢玩的
//                response.setRechargeParam(rechargeParam);
//            }
//            else if(platformNumber == SGCommonProto.E_PLATFORM_TYPE.PLATFORM_TYPE_APP_STORE_VALUE)
//            {
//                JSONObject out = new JSONObject();
//                out.put("outTradeNo", outTradeNo);
//                out.put("rechargeParam", rechargeParam);
//                response.setRechargeParam(out.toJSONString());
//            }
//            else if(platformNumber == SGCommonProto.E_PLATFORM_TYPE.PLATFORM_TYPE_APPLE_PINGPING_VALUE)
//            {
//                response.setRechargeParam(rechargeParam);
//            }
//            else
//            {
//                response.setRechargeParam(rechargeParam);
////                LogUtils.error("获取平台类型错误 -> " + playerController.getServerRuleId());
//            }
//        } else {
//            LogUtils.error("暂无此充值类型");
//            playerController.sendWarn(WordFactory.PARAM_ERROR);
//            return;
//        }

        //发送到认证服
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("outTradeNo", outTradeNo);//订单号
        jsonObject.put("objectIndex", playerController.getObjectIndex());
        jsonObject.put("uid", playerController.getObjectIndex());
        jsonObject.put("rechargeId", rechargeId);
        jsonObject.put("money", response.getRmb());
        jsonObject.put("serverId", GameServer.getInstance().getServerId());
        jsonObject.put("virtualCurrencyAmount" ,diamond);
        jsonObject.put("paymentType",PayUtils.getEnumType(rechargeType.name()));
        jsonObject.put("gameVersion",playerController.getClientVersion());
        jsonObject.put("level",playerController.getPlayer().getLv());
        //获取最新通关信息
        jsonObject.put("mission",playerController.getPlayer().getChallengeInfo().getInstanceData().getLastPass());
        jsonObject.put("partner",playerController.getServerRuleId());
        LogUtils.warn(playerController.getName() + " - > 冲值初始化参数  -> " + jsonObject);
        JSONObject httpResult = HttpJsonUtils.httpPost(GameServer.getInstance().getAuthServerHost() + HttpFactory.PAY_INIT, jsonObject);
        if(httpResult != null && httpResult.containsKey("code") && httpResult.getString("code").equals("0000"))
        {
            //认证服务器初始化冲值成功
            LogUtils.debug("返回给客户端充值验证:" + response);
            playerController.sendMsg(code, response.build().toByteArray());
        }
        else
        {
            LogUtils.error("冲值初始化失败，请检查认证服initRecharge接口 -> " + httpResult);
            playerController.sendWarn(WordFactory.PARAM_ERROR);
        }
    }

    private void rechargeVerify(PlayerController playerController, int code, byte[] data)
    {
        SGPlayerProto.C2S_RechargeVerify request = null;
        try {
            request = SGPlayerProto.C2S_RechargeVerify.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null || Utils.isNullOrEmpty(request.getOutTradeNo())) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        if(request.getRechargeType() == SGCommonProto.E_RECHARGE_TYPE.RECHARGE_TYPE_APPSTORE)
        {
            JSONObject jsonObject = JSONObject.parseObject(request.getParam());
            String payload = jsonObject.getString("Payload");//苹果的参数名
            String transactionId = jsonObject.getString("TransactionID");//苹果的参数名
            if(Utils.isNullOrEmpty(transactionId) || Utils.isNullOrEmpty(payload))
            {
                LogUtils.error("苹果验证需要的参数错误 -> transactionId:" + transactionId);
                playerController.sendWarn(WordFactory.PARAM_ERROR);
                return;
            }
            String outTradeNo = request.getOutTradeNo();
            LogUtils.info("开始验证 -> " + outTradeNo);
            if(GameServer.getInstance().getWorldManager().isVerifying(outTradeNo))
            {
                LogUtils.error("订单->" + outTradeNo + "正在验证中!");
                playerController.sendWarn(WordFactory.APPSTORE_VERIFY_ING);
                return;
            }

            GameServer.getInstance().getWorldManager().verifyTradeStart(outTradeNo);

            LogUtils.info("outTradeNo:" + outTradeNo + ",苹果支付验证 -> " + request.getParam());

            AppStoreNotifyParam param = new AppStoreNotifyParam();
            param.setOutTradeNo(outTradeNo);
            param.setPlayerIndex(playerController.getObjectIndex());
            param.setPayload(payload);
            param.setTransactionId(transactionId);
            param.setServerId(GameServer.getInstance().getServerId());
            param.setServerRuleId(playerController.getServerRuleId());
            param.setPlayerLv(playerController.getPlayer().getLv());
            param.setGameVersion(playerController.getClientVersion());

            String url = GameServer.getInstance().getAuthServerHost() + HttpFactory.PAY_NOTIFY_APPLEPAY;

            JSONObject httpResult = HttpJsonUtils.httpPost(url, JSONObject.parseObject(JSONObject.toJSONString(param)));
            //发送到认证服，异步去苹果验证，同步的不处理
            if(httpResult == null)
            {
                //发送失败
                LogUtils.error("发送验证信息给认证服失败 -> " + url);
                GameServer.getInstance().getWorldManager().verifyTradeEnd(outTradeNo);
                playerController.sendWarn(WordFactory.PARAM_ERROR);
            }
            else
            {
                if(httpResult.containsKey("code") && !httpResult.getString("code").equals(ReturnMessage.SUCCESS.getCode()))
                {
                    LogUtils.error("认证服务器返回错误信息 -> " + httpResult.getString("message"));
                    playerController.sendWarn(httpResult.getString("message"));
                    GameServer.getInstance().getWorldManager().verifyTradeEnd(outTradeNo);
                }
                else
                {
                    //发送成功，等待认证服主动通知，不在这里处理
                }
            }
        }
        else
        {
            LogUtils.error("暂时没有此类型冲值验证");
            playerController.sendWarn(WordFactory.PARAM_ERROR);
        }
    }


    /**
     * 领取首冲礼包奖励
     *
     * @param playerController
     * @param code
     * @param data
     */
    private void receiveFirstRechargeReward(PlayerController playerController, int code, byte[] data) {
        //首冲礼包 读取配置（目前还没有）发放奖励
        StableDataConfig stableDataConfig = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY, E_StableDataType.FIRST_RECHARGE.getCode());
        if (stableDataConfig == null) {
            playerController.sendWarn(WordFactory.CONFIG_NOT_EXIST);
            return;
        }
        if (!playerController.getPlayer().getRechargeData().isFirstRechargeComplete()) {
            LogUtils.debug("没有完成首冲，不能领取首冲奖励");
            playerController.sendWarn(WordFactory.FIRST_RECHARGE_NOT_COMPLETE);
            return;
        }

        BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
        BonusData bonusData = playerController.getPlayer().getBonusData();
        if (bonusData.isFistRechargeReceive()) {
            LogUtils.error("首冲礼包已经领取过了");
            playerController.sendWarn(WordFactory.FIRST_RECHARGE_HAS_RECEIVE);
            return;
        }

        bagInfo.addGoods(stableDataConfig.goods, null);
        bonusData.setFistRechargeReceive(true);
        playerController.sendMsg(code, SGPlayerProto.S2C_ReceiveFirstRechargeReward.newBuilder().build().toByteArray());
    }

    /**
     * 福利面板的初始化
     *
     * @param playerController
     * @param code
     * @param data
     */
    private void bonusBoardInit(PlayerController playerController, int code, byte[] data) {

        SGPlayerProto.C2S_BonusBoardInit request = null;
        try {
            request = SGPlayerProto.C2S_BonusBoardInit.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        RechargeRecordData recordData = playerController.getPlayer().getRechargeRecordData();
        BonusData bonusData = playerController.getPlayer().getBonusData();
        SGPlayerProto.S2C_BonusBoardInit.Builder response = SGPlayerProto.S2C_BonusBoardInit.newBuilder();

        RechargeConfig rechargeConfig = null;
        for(Map.Entry<Integer, RechargeRecordData.MouthCardRecord> entry : recordData.getRechargeRecordMap().entrySet())
        {
            rechargeConfig = DataFactory.getInstance().getGameObject(DataFactory.RECHARGE_KEY, entry.getKey());
            if (rechargeConfig.type == E_RechargeGoodsType.MOUTH_CARD.getCode() || rechargeConfig.type == E_RechargeGoodsType.WEEK_CARD.getCode()) {
                //获取月卡剩余天数
                long endTime = entry.getValue().getEndTime();
                if (DataFactory.currentTime <= endTime) {
                    //获取剩余天数
                    int day = CoreUtils.getBetweenDay24(DataFactory.currentTime, endTime);
                    if (day != 0) {
                        response.addMouthCards(SGCommonProto.MouthCard.newBuilder().
                                setId(entry.getKey()).
                                setEndDays(day).
                                setHasRewardToday(recordData.isMouthCardRewardToday(entry.getKey())).
                                build());
                    }
                }
            }
        }

        response.setHasSignMaxDay(bonusData.getMaxSignRecord());
        String dayNowString = TimeUtils.getFormatTime(DataFactory.currentTime, TimeUtils.DD);
        response.setDay(Integer.valueOf(dayNowString));

        response.setIsOpenFundBuy(bonusData.isFundBuy(SGCommonProto.E_FUND_TYPE.FUND_TYPE_OPEN));
        if (bonusData.isFundBuy(SGCommonProto.E_FUND_TYPE.FUND_TYPE_OPEN)) {
            response.addAllOpenFundRewardRecord(bonusData.getFundReceiverRecord(SGCommonProto.E_FUND_TYPE.FUND_TYPE_OPEN));
        }
        response.setReissueTimes(bonusData.getReissueTimes());
        response.setHasSignToday(bonusData.isSignToday());

//        response.setIsFirstRechargeComplete(recordData.isFirstRechargeComplete());
//        if(recordData.isFirstRechargeComplete()){
//            response.setIsFirstRechargeGiftReward(bonusData.isFistRechargeReceive());
//        }

        response.setDailySignRewardIndex(bonusData.getSignRewardIndex());
        response.setCurrentServerTime(DataFactory.currentTime);
        response.setNextDayOffsetTime(CoreUtils.getNextDayStartOffsetMills(DataFactory.currentTime));
        response.addAllDailyRechargeIds(recordData.getDailyGiftRecordList());

        response.setTotalLoginDaysForNewFund(bonusData.getLoginTimesByDayForNewFund());
        response.setNewServerFundHasBuy(bonusData.isFundBuy(SGCommonProto.E_FUND_TYPE.FUND_TYPE_NEW_SERVER));
        response.addAllNewServerFundRewardIds(bonusData.getFundReceiverRecord(SGCommonProto.E_FUND_TYPE.FUND_TYPE_NEW_SERVER));
        response.addAllTotalRechargeRewardIds(bonusData.getFundReceiverRecord(SGCommonProto.E_FUND_TYPE.FUND_TYPE_TOTAL_RECHARGE));
        response.setTotalRechargeDiamondCount(playerController.getPlayer().getVipExp() / 10);

        response.addAllEveryDayTotalRechargeRewardIds(bonusData.getFundReceiverRecord(SGCommonProto.E_FUND_TYPE.FUND_TYPE_DAILY_TOTAL_RECHARGE));
        response.setEveryDayTotalRechargeDiamondCount(recordData.getRechargeCount(E_QueryRechargeCountType.DAILY.getCode()));

        //当日累计消耗钻石
        response.setEveryDayTotalConsumeDiamondCount(bonusData.getDiamondsCacheDaily());
        response.addAllEveryDayTotalConsumeRewardIds(bonusData.getFundReceiverRecord(SGCommonProto.E_FUND_TYPE.FUND_TYPE_DAILY_TOTAL_CONSUME));

        //限时活动
        List<TimeLimitedActivitiesConfig> configs = DataFactory.getInstance().getDataList(DataFactory.TIME_LIMIT_ACTIVITY_KEY);
        for (TimeLimitedActivitiesConfig config : configs) {
            if (config.isTimeInForReceiver() && config.isServerIn(WorldInfoFactory.getInstance().getServerId()) &&
                    config.isPlatformIn(CoreUtils.formRuleId(playerController.getServerRuleId())[2])) {
                SGCommonProto.KeyListObject.Builder object = SGCommonProto.KeyListObject.newBuilder();
                object.setKey(config.id);
                if (bonusData.getActivityRecord().get(config.id) != null) {
                    object.addAllList(bonusData.getActivityRecord().get(config.id).getRecordList());
                }
                object.setValue(recordData.getRechargeCount(E_QueryRechargeCountType.DEFINE.getCode()));
                response.addTimeLimitActivity(object.build());
            }
        }

        ShareData shareData = playerController.getPlayer().getShareData();
        response.addAllShareList(shareData.getShareObjectList());
        LogUtils.debug("返回给客户端福利面板信息" + response.toString());
        playerController.sendMsg(code, response.build().toByteArray());

    }

    /**
     * 累计登陆奖励领取
     *
     * @param playerController
     * @param code
     * @param data
     */
    private void receiveLoginTimesReward(PlayerController playerController, int code, byte[] data) {
        SGPlayerProto.C2S_ReceiveLoginTimesReward request = null;
        try {
            request = SGPlayerProto.C2S_ReceiveLoginTimesReward.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        int rewardId = request.getRewardId();
        LogUtils.debug("领取累计登录奖励参数:" + request.toString());
        BonusData bonusData = playerController.getPlayer().getBonusData();
        LoginTimesBonusConfig bonusConfig = DataFactory.getInstance().getGameObject(DataFactory.LOGIN_TIMES_REWARD_KEY, rewardId);
        if (bonusConfig == null || bonusData.getLoginTimesByDay() < bonusConfig.id) {
            LogUtils.error("配置找不到，或者累计登录天数未达到");
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        if (bonusData.isLoginTimesRewardReceive(rewardId)) {
            LogUtils.error("奖励已经领取过了");
            playerController.sendWarn(WordFactory.GET_REWARD_ED);
            return;
        }

        bonusData.addLoginTimesRewardReceive(rewardId);
        BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
        bagInfo.addGoods(bonusConfig.reward, null);
        playerController.sendMsg(code, SGPlayerProto.S2C_ReceiveLoginTimesReward.newBuilder().setRewardId(rewardId).build().toByteArray());
    }

    /**
     * 登录次数奖励初始化
     *
     * @param playerController
     * @param code
     * @param data
     */
    private void loginTimesRewardInit(PlayerController playerController, int code, byte[] data) {
        BonusData bonusData = playerController.getPlayer().getBonusData();
        SGPlayerProto.S2C_LoginTimesRewardInit.Builder response = SGPlayerProto.S2C_LoginTimesRewardInit.newBuilder();
        response.setTotalLoginDays(bonusData.getLoginTimesByDay());
        response.addAllHasReceiveId(bonusData.getLoginRewardRecord());
        playerController.sendMsg(code, response.build().toByteArray());
    }

    /**
     * 领取基金奖励
     *
     * @param playerController
     * @param code
     * @param data
     */
    private void receiveFundReward(PlayerController playerController, int code, byte[] data) {
        SGPlayerProto.C2S_ReceiveFundReward request = null;
        try {
            request = SGPlayerProto.C2S_ReceiveFundReward.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        LogUtils.debug("领取基金奖励参数:" + request.toString());
        if (request.getFundType() == null || request.getFundType() == SGCommonProto.E_FUND_TYPE.FUND_TYPE_UNKNOW) {
            LogUtils.error("暂无此基金类型" + request.getFundType());
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        int rewardId = request.getRewardId();
        FundRewardConfig rewardConfig = DataFactory.getInstance().getGameObject(DataFactory.FUND_REWARD_KEY, rewardId);
        if (rewardConfig == null || rewardConfig.type != request.getFundTypeValue()) {
            LogUtils.error("配置找不到，或者配置类型错误");
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        BonusData bonusData = playerController.getPlayer().getBonusData();
        if (bonusData.isFundRewardReceive(request.getFundType(), rewardId)) {
            LogUtils.error("基金对应奖励已经领取过了");
            playerController.sendWarn(WordFactory.GET_REWARD_ED);
            return;
        }

        if (request.getFundType() == SGCommonProto.E_FUND_TYPE.FUND_TYPE_OPEN) {
            if (!bonusData.isFundBuy(request.getFundType())) {
                LogUtils.error("基金还未购买");
                playerController.sendWarn(WordFactory.FUND_HAS_NOT_BUY);
                return;
            }
            if (playerController.getPlayer().getLv() < rewardConfig.minlv) {
                LogUtils.error("开服基金领取奖励等级不足, 当前等级" + playerController.getPlayer().getLv() + ",   需要等级：" + rewardConfig.minlv);
                playerController.sendWarn(WordFactory.LEVEL_NOT_ENOUGH);
                return;
            }
        } else if (request.getFundType() == SGCommonProto.E_FUND_TYPE.FUND_TYPE_NEW_SERVER) {
            if (!bonusData.isFundBuy(request.getFundType())) {
                LogUtils.error("基金还未购买");
                playerController.sendWarn(WordFactory.FUND_HAS_NOT_BUY);
                return;
            }
            if (playerController.getPlayer().getBonusData().getLoginTimesByDayForNewFund() < rewardConfig.minlv) {
                LogUtils.error("新区领取奖励登录天数不足, 当前天数" + playerController.getPlayer().getBonusData().getLoginTimesByDayForNewFund() +
                        ",   需要天数：" + rewardConfig.minlv);
                playerController.sendWarn(WordFactory.LEVEL_NOT_ENOUGH);
                return;
            }
        } else if (request.getFundType() == SGCommonProto.E_FUND_TYPE.FUND_TYPE_TOTAL_RECHARGE) {
            if (playerController.getPlayer().getVipExp() / 10 < rewardConfig.minlv) {
                LogUtils.error("充值数量不足, 当前" + playerController.getPlayer().getVipExp() + ",   需要：" + rewardConfig.minlv);
                playerController.sendWarn(WordFactory.RECHARGE_NOT_ENOUGH);
                return;
            }
        } else if (request.getFundType() == SGCommonProto.E_FUND_TYPE.FUND_TYPE_DAILY_TOTAL_RECHARGE) {
            int total = playerController.getPlayer().getRechargeData().getRechargeCount(E_QueryRechargeCountType.DAILY.getCode());
            if (total < rewardConfig.minlv) {
                LogUtils.error("充值数量不足, 当前" + total + ",   需要：" + rewardConfig.minlv);
                playerController.sendWarn(WordFactory.RECHARGE_NOT_ENOUGH);
                return;
            }
        } else if (request.getFundType() == SGCommonProto.E_FUND_TYPE.FUND_TYPE_DAILY_TOTAL_CONSUME) {
            int total = bonusData.getDiamondsCacheDaily();
            if (total < rewardConfig.minlv) {
                LogUtils.error("钻石消耗不足, 当前" + total + ",   需要：" + rewardConfig.minlv);
                playerController.sendWarn(WordFactory.CONSUME_DIAMONDS_NOT_ENOUGH);
                return;
            }
        } else {
            LogUtils.error("暂无此基金类型" + request.getFundType());
            playerController.sendWarn(WordFactory.PARAM_ERROR);
        }

        BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
        bagInfo.addGoods(rewardConfig.reward, null);
        bonusData.addFundRewardRecord(request.getFundType(), rewardId);
        playerController.sendMsg(code, SGPlayerProto.S2C_ReceiveFundReward.newBuilder().setFundType(request.getFundType()).
                setRewardId(rewardId).build().toByteArray());
    }

    /**
     * 购买基金 暂时不用
     *
     * @param playerController
     * @param code
     * @param data
     */
    private void buyFund(PlayerController playerController, int code, byte[] data) {
        SGPlayerProto.C2S_BuyFund request = null;
        try {
            request = SGPlayerProto.C2S_BuyFund.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

//        if(request.getFundType() == SGCommonProto.E_FUND_TYPE.FUND_TYPE_OPEN){//开服基金
//            BonusData bonusData = playerController.getPlayerResult().getBonusData();
//            if(bonusData.isBuyOpenFund()){
//                LogUtils.debug("开服基金已经购买过");
//                playerController.sendWarn(WordFactory.FUND_HAS_BUY);
//                return;
//            }
//
//            StableDataConfig stableDataConfig = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY, E_StableDataType.OPEN_FUND_PRICE.getCode());
//            if(playerController.getPlayerResult().getVipLevel() < stableDataConfig.intValue){
//                LogUtils.debug("vip等级不足 需要：" + stableDataConfig.intValue + ", 当前vip等级：" + playerController.getPlayerResult().getVipLevel());
//                playerController.sendWarn(WordFactory.VIP_LEVEL_NOT_ENOUGH);
//                return;
//            }
//            BagInfo bagInfo = playerController.getPlayerResult().getExtInfo(BagInfo.class);
//            int count = bagInfo.getGoodsCount(stableDataConfig.goods[0].type, stableDataConfig.goods[0].id);
//            if( count < stableDataConfig.goods[0].value){
//                LogUtils.debug("钻石资源不足,需要：" + stableDataConfig.goods[0].value + "，拥有：" +    count);
//                playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, stableDataConfig.goods[0].id);
//                return;
//            }
//
//            bagInfo.addGoods(new GoodsData[0], stableDataConfig.goods);
//            bonusData.buyOpenFund();
//
//            playerController.sendMsg(code, SGPlayerProto.S2C_BuyFund.newBuilder().setFundType(request.getFundType()).build().toByteArray());
//        }else {
        LogUtils.error("暂无此基金类型" + request.getFundType());
        playerController.sendWarn(WordFactory.PARAM_ERROR);
        return;
//        }
    }

    /**
     * 每日签到
     *
     * @param playerController
     * @param code
     * @param data
     */
    private void dailySignReward(PlayerController playerController, int code, byte[] data) {
        BonusData bonusData = playerController.getPlayer().getBonusData();
        int maxDayRecord = bonusData.getMaxSignDay();
        String dayNowString = TimeUtils.getFormatTime(DataFactory.currentTime, TimeUtils.DD);
        int dayNow = Integer.valueOf(dayNowString);
        LogUtils.debug("每日签到 当前日期:" + dayNow + ", 已签到的最大日期:" + maxDayRecord);
        if (maxDayRecord >= dayNow) {
            LogUtils.error("当前已经没有可签到的天数了");
            playerController.sendWarn(WordFactory.DAILY_SIGN_FULL);
            return;
        }

        int nextDay = maxDayRecord + 1;
        DailySignRewardConfig dailySignRewardConfig = DataFactory.getInstance().getGameObject(DataFactory.DAILY_SIGN_KEY, nextDay);
        if (dailySignRewardConfig == null) {
            LogUtils.error("本月已经签到完毕");
            playerController.sendWarn(WordFactory.DAILY_SIGN_FULL);
            return;
        }

        BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
        if (bonusData.isSignToday()) {
            //需要补签
            PurchaseTimesConfig timesConfig = DataFactory.getInstance().getGameObject(DataFactory.PURCHASE_KEY, bonusData.getReissueTimes() + 1);
            int hasCount = bagInfo.getGoodsCount(timesConfig.reissueDailySign[0].type, timesConfig.reissueDailySign[0].id);
            if (hasCount < timesConfig.reissueDailySign[0].value) {//自己拥有小于配置的
                LogUtils.debug("每日签到补签资源不足 自己拥有:" + hasCount + "     ,需要：" + timesConfig.reissueDailySign[0].value);
                playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, timesConfig.reissueDailySign[0].id);
                return;
            }
            bagInfo.addGoods(new GoodsData[0], timesConfig.reissueDailySign);
            bonusData.addReissueTimes();
        }

        bonusData.addSignRecord(dailySignRewardConfig.id, DataFactory.currentTime);


        GoodsData src = dailySignRewardConfig.reward[bonusData.getSignRewardIndex()];
        bagInfo.addGoods(new GoodsData(src.type, src.id,
                playerController.getPlayer().getVipLevel() >= dailySignRewardConfig.doubleVipLevel ? src.value * 2 : src.value));

        playerController.sendMsg(code, SGPlayerProto.S2C_DailySignReward.newBuilder().
                setDayId(dailySignRewardConfig.id).
                setReissueTimes(bonusData.getReissueTimes()).build().toByteArray());

    }

    /**
     * 充值的初始化
     *
     * @param playerController
     * @param code
     */
    private void rechargeInit(PlayerController playerController, int code) {
        SGPlayerProto.S2C_RechargeInit.Builder response = SGPlayerProto.S2C_RechargeInit.newBuilder();
        response.setVipExp(playerController.getPlayer().getVipExp());
        response.setVipLv(playerController.getPlayer().getVipLevel());
        RechargeRecordData rechargeRecordData = playerController.getPlayer().getRechargeRecordData();
        response.addAllVipLvs(rechargeRecordData.getGiftBagRecordList());

        RechargeConfig rechargeConfig = null;
        for(Map.Entry<Integer, RechargeRecordData.MouthCardRecord> entry : rechargeRecordData.getRechargeRecordMap().entrySet())
        {
            rechargeConfig = DataFactory.getInstance().getGameObject(DataFactory.RECHARGE_KEY, entry.getKey());
            if (rechargeConfig.type == E_RechargeGoodsType.MOUTH_CARD.getCode()) {
                //获取月卡剩余天数
                long endTime = entry.getValue().getEndTime();
                if (DataFactory.currentTime <= endTime) {
                    //获取剩余天数
                    int day = CoreUtils.getBetweenDay24(DataFactory.currentTime, endTime);
                    if (day != 0) {
                        //只剩一天了，并且今天已经领取了，不在下发给客户端
//                        if (day == 1 && rechargeRecordData.isMouthCardRewardToday(key)) {
//                            continue;
//                        } else {
                        response.addMouthCards(SGCommonProto.MouthCard.newBuilder().
                                setId(entry.getKey()).
                                setEndDays(day).
                                setHasRewardToday(rechargeRecordData.isMouthCardRewardToday(entry.getKey())).
                                build());
                        //}
                    }
                }
            } else if (rechargeConfig.type == E_RechargeGoodsType.DIAMOND.getCode()) {
                response.addHasBuyRechargeId(entry.getKey());
            }
        }

        response.setCurrentServerTime(CoreUtils.getNextDayStartOffsetMills(DataFactory.currentTime));
        LogUtils.debug("返回给客户端充值初始化信息" + response);
        playerController.sendMsg(code, response.build().toByteArray());
    }

    /**
     * 购买vip礼包
     *
     * @param playerController
     * @param code
     * @param data
     */
    private void buyVipGiftBag(PlayerController playerController, int code, byte[] data) {
        SGPlayerProto.C2S_BuyVipGiftBag request = null;
        try {
            request = SGPlayerProto.C2S_BuyVipGiftBag.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        int targetVipLv = request.getVipLv();
        LogUtils.debug("vip礼包购买目标vipLv:" + targetVipLv);
        VipConfig vipConfig = DataFactory.getInstance().getGameObject(DataFactory.VIP_KEY, targetVipLv);
        if (vipConfig == null) {
            LogUtils.error("找不到对应vip配置");
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        if (playerController.getPlayer().getVipLevel() < targetVipLv) {
            LogUtils.error("vip等级不足");
            playerController.sendWarn(WordFactory.VIP_LEVEL_NOT_ENOUGH, targetVipLv);
            return;
        }

        RechargeRecordData rechargeRecordData = playerController.getPlayer().getRechargeRecordData();
        if (rechargeRecordData.hasGiftBagForVipId(targetVipLv)) {
            LogUtils.error("礼包已经购买过了");
            playerController.sendWarn(WordFactory.VIP_GIFT_BAG_ALREADY_BUY);
            return;
        }

        BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);

        if (playerController.getPlayer().money < vipConfig.discountPrice) {
            LogUtils.debug("钻石不足，拥有" + playerController.getPlayer().money + ", 需要：" + vipConfig.discountPrice);
            playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, ConfigFactory.ASSET_MONEY_KEY);
            return;
        }

        rechargeRecordData.addGiftBagVipId(targetVipLv);

        DropGroupConfig dropGroupConfig = DataFactory.getInstance().getGameObject(DataFactory.DROP_GROUP_KEY, vipConfig.gift);
        dropGroupConfig.reward(playerController);

        bagInfo.addAsset(ConfigFactory.ASSET_MONEY_KEY, -vipConfig.discountPrice);

        SGPlayerProto.S2C_BuyVipGiftBag.Builder response = SGPlayerProto.S2C_BuyVipGiftBag.newBuilder();
        response.setVipLv(targetVipLv);
        playerController.sendMsg(code, response.build().toByteArray());
    }

    /**
     * 领取月卡奖励
     *
     * @param playerController
     * @param code
     * @param data
     */
    private void receiveMouthCardReward(PlayerController playerController, int code, byte[] data) {
        SGPlayerProto.C2S_ReceiveMouthCardReward request = null;
        try {
            request = SGPlayerProto.C2S_ReceiveMouthCardReward.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        LogUtils.debug("领取月卡奖励参数:" + request.toString());
        int rechargeId = request.getRecharId();
        RechargeConfig rechargeConfig = DataFactory.getInstance().getGameObject(DataFactory.RECHARGE_KEY, rechargeId);
        if (rechargeConfig == null || !(rechargeConfig.type == E_RechargeGoodsType.MOUTH_CARD.getCode() ||
                rechargeConfig.type == E_RechargeGoodsType.WEEK_CARD.getCode())) {
            LogUtils.error("月卡找不到...");
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        RechargeRecordData recordData = playerController.getPlayer().getRechargeRecordData();
        if (recordData.hasRechargeRecord(rechargeId)) {//曾经购买过
            //这里根据剩余天数判断月卡是否过期
            long endTime = recordData.getRechargeRecordMap().get(rechargeId).getEndTime();
            int days = CoreUtils.getBetweenDay24(DataFactory.currentTime, endTime);
            if (days <= 0) { //已过期
                LogUtils.error("月卡未购买");
                playerController.sendWarn(WordFactory.MOUTH_CARD_NOT_BUY);
                return;
            }
        } else {
            LogUtils.error("月卡未购买");
            playerController.sendWarn(WordFactory.MOUTH_CARD_NOT_BUY);
            return;
        }


        if (recordData.isMouthCardRewardToday(rechargeId)) {
            LogUtils.error("月卡奖励今天已经领取过了");
            playerController.sendWarn(WordFactory.MOUTH_CARD_HAS_REWARD_TODAY);
            return;
        }

        recordData.recordMouthCardRewardTime(rechargeId, DataFactory.currentTime);

        //发放奖励
        BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
        bagInfo.addGoods(rechargeConfig.extra, null);

        playerController.sendMsg(code, SGPlayerProto.S2C_ReceiveMouthCardReward.newBuilder().
                setRecharId(rechargeId).
                setNextRewardOffsetTime(CoreUtils.getNextDayStartOffsetMills(DataFactory.currentTime)).build().toByteArray());


    }

    /**
     * 挑战次数购买
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void buyTimes(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_StoreBuyTimes request = null;
        try {
            request = SGPlayerProto.C2S_StoreBuyTimes.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        LogUtils.debug("挑战次数购买参数:" + request.toString());
        int times = request.getTimes();
        if (times <= 0) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        times = times <= 0 ? 1 : times;
        switch (request.getType().getNumber()) {
            case SGCommonProto.E_BUY_TIMES_TYPE.BUY_TIMES_TYPE_ARENA_VALUE:
                buyArenaChallengeTimes(playerController, times, code);
                break;
            case SGCommonProto.E_BUY_TIMES_TYPE.BUY_TIMES_TYPE_OFFICIAL_RANK_VALUE:
                buyOfficialRankChallengeTimes(playerController, times, code);
                break;
            case SGCommonProto.E_BUY_TIMES_TYPE.BUY_TIMES_TYPE_HERO_TEMPLE_VALUE:
//                buyHeroTempleChallengeTimes(playerController, intValue, code);
                break;
            case SGCommonProto.E_BUY_TIMES_TYPE.BUY_TIMES_TYPE_EXPEDITION_VALUE:
                buyExpeditionResetTimes(playerController, times, code);
                break;
            case SGCommonProto.E_BUY_TIMES_TYPE.BUY_TIMES_TYPE_EXPEDITION_CHALLENGE_VALUE:
                buyExpeditionChallengeTimes(playerController, times, code);
                break;
            case SGCommonProto.E_BUY_TIMES_TYPE.BUY_TIMES_TYPE_WORLD_BOSS_VALUE:
                buyWorldBossChallengeTimes(playerController, times, code);
                break;
        }


    }

    /**
     * 远征挑战次数购买
     *
     * @param playerController
     * @param times
     * @param code
     */
    private void buyExpeditionChallengeTimes(PlayerController playerController, int times, int code) {
        ExpeditionData expeditionData = playerController.getPlayer().getExpeditionData();
        StableDataConfig stableDataConfig = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY, E_StableDataType.EXPEDITION_TOTAL_CHALLENGE_TIMES.getCode());
        if (expeditionData.getTodayTotalChallengeTimes() + times > stableDataConfig.intValue) {
            LogUtils.debug("远征购买已经达到最大值,今日最大挑战次数：" + expeditionData.getTodayTotalChallengeTimes() +
                    ", 配置:" + stableDataConfig.intValue);
            playerController.sendWarn(WordFactory.EXPEDITION_BUY_TIMES_TOUCH_MAX);
            return;
        }

        stableDataConfig = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY, E_StableDataType.EXPEDITION_CHALLENGE_TIMES_BUY.getCode());
        GoodsData goodsData = new GoodsData(stableDataConfig.goods[0].type, stableDataConfig.goods[0].id, stableDataConfig.goods[0].value * times);


        BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
        int hasCount = bagInfo.getGoodsCount(goodsData.type, goodsData.id);
        if (hasCount < goodsData.value) {//自己拥有小于配置的
            LogUtils.debug("远征购买次数资源不足 自己拥有:" + hasCount + "     ,需要：" + goodsData.value);
            playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, goodsData.id);
            return;
        }

        expeditionData.addTodayTotalChallengeTime(times);
        bagInfo.addGoods(new GoodsData[0], new GoodsData[]{goodsData});

        SGPlayerProto.S2C_StoreBuyTimes.Builder response = SGPlayerProto.S2C_StoreBuyTimes.newBuilder();
        response.setTimes(times);
        response.setTotalTimes(expeditionData.getTodayTotalChallengeTimes());
        response.setType(SGCommonProto.E_BUY_TIMES_TYPE.BUY_TIMES_TYPE_EXPEDITION_CHALLENGE);
        playerController.sendMsg(code, response.build().toByteArray());
    }

    /**
     * boss挑战次数购买
     *
     * @param playerController
     * @param times
     * @param code
     */
    private void buyWorldBossChallengeTimes(PlayerController playerController, int times, int code) {
        VipConfig vipConfig = DataFactory.getInstance().getGameObject(DataFactory.VIP_KEY,playerController.getPlayer().getVipLevel());
        BossData bossData = playerController.getPlayer().getBossData();
        int alreadyBuyTimes = bossData.getAlreadyBuyTimes(vipConfig);
        if (alreadyBuyTimes + times > vipConfig.buyBossMax){
            LogUtils.debug("BOSS战购买次数超过限制最多购买次数:" + vipConfig.buyBossMax + " ,实际购买了:" + (alreadyBuyTimes + times));
            playerController.sendWarn(WordFactory.BOSS_BUY_CHALLENGE_TIME_OVERRUN);
            return;
        }
        StableDataConfig stableDataConfig = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY,
                E_StableDataType.BOSS_CHALLENGE_BUY.getCode());
        /**
         * 第一次购买扣除第一次的钱 第二次购买扣除第二次的钱
         * 超出后按照最后一次价格算
         */
        GoodsData[] goods = stableDataConfig.goods;
        GoodsData goodsData = new GoodsData(goods[0].type, goods[0].id, 0);
        /**
         * 第几次购买与stable的length进行比较
         * 如果大于等于length 增加length-1 的钻石
         * 如果小于length 增加 already + i - 1 的钻石
         */
        for (int i = 1; i <= times; i ++){
            if (i + alreadyBuyTimes >= stableDataConfig.goods.length){
                goodsData.value += goods[goods.length - 1].value;
            }else{
                goodsData.value += goods[alreadyBuyTimes + i - 1].value;
            }
        }
        BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
        int hasCount = bagInfo.getGoodsCount(goodsData.type, goodsData.id);
        if (hasCount < goodsData.value) {//自己拥有小于配置的
            LogUtils.debug("世界boss购买次数资源不足 自己拥有:" + hasCount + "     ,需要：" + goodsData.value);
            playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, goodsData.id);
            return;
        }

        bossData.addTodayTotalChallengeTime(times);
        bagInfo.addGoods(new GoodsData[0], new GoodsData[]{goodsData});

        SGPlayerProto.S2C_StoreBuyTimes.Builder response = SGPlayerProto.S2C_StoreBuyTimes.newBuilder();
        response.setTimes(times);
        response.setTotalTimes(bossData.getTodayTotalChallengeTimes());
        response.setType(SGCommonProto.E_BUY_TIMES_TYPE.BUY_TIMES_TYPE_WORLD_BOSS);
        playerController.sendMsg(code, response.build().toByteArray());
    }

    /**
     * 远征重置次数购买
     *
     * @param playerController
     * @param times
     * @param code
     */
    private void buyExpeditionResetTimes(PlayerController playerController, int times, int code) {
        VipConfig vipConfig = DataFactory.getInstance().getGameObject(DataFactory.VIP_KEY, playerController.getPlayer().getVipLevel());
        ExpeditionData expeditionData = playerController.getPlayer().getExpeditionData();
        int hasBuyTimes = expeditionData.getTodayTotalResetTimes() - vipConfig.expeditionFreeTimes;
        if (hasBuyTimes + times > vipConfig.expeditionPurchaseMax) { //超过vip限制
            LogUtils.debug("远征购买次数超过限制最多购买次数:" + vipConfig.buyArenaMax + "  , 实际购买了:" + (hasBuyTimes + times));
            playerController.sendWarn(WordFactory.ARENA_BUY_CHALLENGE_TIME_OVERRUN);
            return;
        }
        PurchaseTimesConfig timesConfig;
        GoodsData goodsData = null;
        //计算购买的总价格
        for (int i = 1; i <= times; i++) {
            int targetTimes = i + hasBuyTimes;
            timesConfig = DataFactory.getInstance().getGameObject(DataFactory.PURCHASE_KEY, targetTimes);
            if (goodsData == null) {
                goodsData = new GoodsData(timesConfig.expeditionBuyPrice[0].type, timesConfig.expeditionBuyPrice[0].id,
                        timesConfig.expeditionBuyPrice[0].value);
            } else {
                goodsData.value += timesConfig.expeditionBuyPrice[0].value;
            }
        }
        if (goodsData != null) {
            BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
            int hasCount = bagInfo.getGoodsCount(goodsData.type, goodsData.id);
            if (hasCount < goodsData.value) {//自己拥有小于配置的
                LogUtils.debug("远征副本购买次数资源不足 自己拥有:" + hasCount + "     ,需要：" + goodsData.value);
                playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, goodsData.id);
                return;
            }

            expeditionData.addTodayTotalResetTime(times);
            bagInfo.addGoods(new GoodsData[0], new GoodsData[]{goodsData});

            SGPlayerProto.S2C_StoreBuyTimes.Builder response = SGPlayerProto.S2C_StoreBuyTimes.newBuilder();
            response.setTimes(times);
            response.setTotalTimes(expeditionData.getTodayTotalResetTimes());
            response.setType(SGCommonProto.E_BUY_TIMES_TYPE.BUY_TIMES_TYPE_EXPEDITION);
            playerController.sendMsg(code, response.build().toByteArray());

        } else {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }


    }

    /**
     * 竞技场次数购买
     *
     * @param playerController
     * @param times
     * @param code
     */
    private void buyArenaChallengeTimes(PlayerController playerController, int times, int code) {
        VipConfig vipConfig = DataFactory.getInstance().getGameObject(DataFactory.VIP_KEY, playerController.getPlayer().getVipLevel());
        ArenaData arenaData = playerController.getPlayer().getArenaData();
        int alreadyBuyTimes = arenaData.getAlreadyBuyTimes();
        if (alreadyBuyTimes + times > vipConfig.buyArenaMax) { //超过vip限制
            LogUtils.debug("竞技场购买次数超过限制最多购买次数:" + vipConfig.buyArenaMax + "  , 实际购买了:" + (arenaData.getAlreadyBuyTimes() + times));
            playerController.sendWarn(WordFactory.ARENA_BUY_CHALLENGE_TIME_OVERRUN);
            return;
        }

        PurchaseTimesConfig timesConfig;
        GoodsData goodsData = null;
        //计算购买的总价格
        for (int i = 1; i <= times; i++) {
            int targetTimes = i + alreadyBuyTimes;
            timesConfig = DataFactory.getInstance().getGameObject(DataFactory.PURCHASE_KEY, targetTimes);
            if (goodsData == null) {
                goodsData = new GoodsData(timesConfig.buyArenaMax[0].type, timesConfig.buyArenaMax[0].id, timesConfig.buyArenaMax[0].value);
            } else {
                goodsData.value += timesConfig.buyArenaMax[0].value;
            }
        }
        if (goodsData != null) {
            BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
            int hasCount = bagInfo.getGoodsCount(goodsData.type, goodsData.id);
            if (hasCount < goodsData.value) {//自己拥有小于配置的
                LogUtils.debug("竞技场购买次数资源不足 自己拥有:" + hasCount + "     ,需要：" + goodsData.value);
                playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, goodsData.id);
                return;
            }

            arenaData.addTodayTotalChallengeTime(times);
            bagInfo.addGoods(new GoodsData[0], new GoodsData[]{goodsData});

            SGPlayerProto.S2C_StoreBuyTimes.Builder response = SGPlayerProto.S2C_StoreBuyTimes.newBuilder();
            response.setTimes(times);
            response.setTotalTimes(arenaData.getRemainTodayChallengeTimes());
            response.setType(SGCommonProto.E_BUY_TIMES_TYPE.BUY_TIMES_TYPE_ARENA);
            playerController.sendMsg(code, response.build().toByteArray());

        } else {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

    }

    /**
     * 官阶战次数购买
     *
     * @param playerController
     * @param times
     * @param code
     */
    private void buyOfficialRankChallengeTimes(PlayerController playerController, int times, int code) {
        OfficialRankData officialData = playerController.getPlayer().getOfficialData();
        StableDataConfig stableDataConfig = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY, E_StableDataType.OFFICIAL_RANK_BUY_PRICE.getCode());


        GoodsData goodsData = new GoodsData(stableDataConfig.goods[0].type, stableDataConfig.goods[0].id, stableDataConfig.goods[0].value * times);

        BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
        int hasCount = bagInfo.getGoodsCount(goodsData.type, goodsData.id);
        if (hasCount < goodsData.value) {//自己拥有小于配置的
            LogUtils.debug("官阶战购买次数资源不足 自己拥有:" + hasCount + "     ,需要：" + goodsData.value);
            playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, goodsData.id);
            return;
        }

        officialData.addTodayTotalChallengeTime(times);
        bagInfo.addGoods(new GoodsData[0], new GoodsData[]{goodsData});

        SGPlayerProto.S2C_StoreBuyTimes.Builder response = SGPlayerProto.S2C_StoreBuyTimes.newBuilder();
        response.setTimes(times);
        response.setTotalTimes(officialData.getTodayRemainChallengeTimes());
        response.setType(SGCommonProto.E_BUY_TIMES_TYPE.BUY_TIMES_TYPE_OFFICIAL_RANK);
        playerController.sendMsg(code, response.build().toByteArray());

    }

    /**
     * 购买商品
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void buyGoods(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_StoreBuyGoods request = null;
        try {
            request = SGPlayerProto.C2S_StoreBuyGoods.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        LogUtils.debug("购买商品请求参数: " + request.toString());
        int goodId = request.getGoodsId();
        int count = request.getCount();
        count = count <= 0 ? 1 : count;
        GoblinStoreConfig goods = DataFactory.getInstance().getGameObject(DataFactory.GOBLIN_STORE_KEY, goodId);
        if (goods == null || goods.storeType != request.getType().getNumber()) {
            LogUtils.error("根据商品id获取商品配置错误");
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
        if (bagInfo.getAsset(goods.price.id) < goods.price.value * count) {//自己拥有的小于配置的
            //<editor-fold desc="Description">
            //TODO 资源不足
            //</editor-fold>
            //需要的资源不够
            LogUtils.debug("购买的价格id-->" + goods.price.id + " 超出价格：" + goods.price.value + ", 自己拥有:" + bagInfo.getAsset(goods.price.id));
            playerController.sendWarn(WordFactory.STORE_GOODS_MONEY_NOT_ENOUGH, goods.price.id);
            return;
        }

        if (request.getType() == SGCommonProto.E_STORE_TYPE.STORE_TYPE_GOBLIN) {
            count = 1;
            BoonInfo boonInfo = playerController.getPlayer().getExtInfo(BoonInfo.class);
            StoreCacheData storeData = boonInfo.getGoblinStoreData().getStoreCache(request.getType().getNumber());
            int index = storeData.getRecords().indexOf(new GoblinStoreRecordData(goodId));
            if (index == -1) {
                LogUtils.error("该物品没有刷新在列表");
                playerController.sendWarn(WordFactory.STORE_GOODS_NOT_REFRESH);
                return;
            }
            GoblinStoreRecordData recordData = storeData.getRecords().get(index);
            if (recordData.isBuy) {
                LogUtils.error("该物品已经购买过");
                playerController.sendWarn(WordFactory.STORE_GOODS_HAS_BUY);
                return;
            }
            //添加购买记录
            recordData.isBuy = true;
            // 检测任务是否完成
            playerController.getPlayer().getExtInfo(TaskInfo.class).check(TaskFactory.TASK_TARAGET_EVERYDAY_GUBLIANSTORE, 1);
        } else if (request.getType() == SGCommonProto.E_STORE_TYPE.STORE_TYPE_ARENA) {
            count = 1;
            BoonInfo boonInfo = playerController.getPlayer().getExtInfo(BoonInfo.class);
            StoreCacheData storeData = boonInfo.getGoblinStoreData().getStoreCache(request.getType().getNumber());
            int index = storeData.getRecords().indexOf(new GoblinStoreRecordData(goodId));
            if (index == -1) {
                LogUtils.error("该物品没有刷新在列表");
                playerController.sendWarn(WordFactory.STORE_GOODS_NOT_REFRESH);
                return;
            }
            GoblinStoreRecordData recordData = storeData.getRecords().get(index);
            if (recordData.isBuy) {
                LogUtils.error("该物品已经购买过");
                playerController.sendWarn(WordFactory.STORE_GOODS_HAS_BUY);
                return;
            }
            //添加购买记录
            recordData.isBuy = true;
        } else if (request.getType() == SGCommonProto.E_STORE_TYPE.STORE_TYPE_EXPEDITION) {
            count = 1;
            BoonInfo boonInfo = playerController.getPlayer().getExtInfo(BoonInfo.class);
            StoreCacheData storeData = boonInfo.getGoblinStoreData().getStoreCache(request.getType().getNumber());
            int index = storeData.getRecords().indexOf(new GoblinStoreRecordData(goodId));
            if (index == -1) {
                LogUtils.error("该物品没有刷新在列表");
                playerController.sendWarn(WordFactory.STORE_GOODS_NOT_REFRESH);
                return;
            }
            GoblinStoreRecordData recordData = storeData.getRecords().get(index);
            if (recordData.isBuy) {
                LogUtils.error("该物品已经购买过");
                playerController.sendWarn(WordFactory.STORE_GOODS_HAS_BUY);
                return;
            }
            //添加购买记录
            recordData.isBuy = true;
        } else if (request.getType() == SGCommonProto.E_STORE_TYPE.STORE_TYPE_EQUIP) {

        } else if (request.getType() == SGCommonProto.E_STORE_TYPE.STORE_TYPE_EXPLOIT) {

        } else if (request.getType() == SGCommonProto.E_STORE_TYPE.STORE_TYPE_DIAMOND) {
            count = 1;
            BoonInfo boonInfo = playerController.getPlayer().getExtInfo(BoonInfo.class);
            StoreCacheData storeData = boonInfo.getGoblinStoreData().getStoreCache(request.getType().getNumber());
            int index = storeData.getRecords().indexOf(new GoblinStoreRecordData(goodId));
            if (index == -1) {
                LogUtils.error("该物品没有刷新在列表");
                playerController.sendWarn(WordFactory.STORE_GOODS_NOT_REFRESH);
                return;
            }
            GoblinStoreRecordData recordData = storeData.getRecords().get(index);
            if (recordData.isBuy) {
                LogUtils.error("该物品已经购买过");
                playerController.sendWarn(WordFactory.STORE_GOODS_HAS_BUY);
                return;
            }
            //添加购买记录
            recordData.isBuy = true;
        } else if (request.getType() == SGCommonProto.E_STORE_TYPE.STORE_TYPE_VIP) {
            count = 1;
            BoonInfo boonInfo = playerController.getPlayer().getExtInfo(BoonInfo.class);
            StoreCacheData storeData = boonInfo.getGoblinStoreData().getStoreCache(request.getType().getNumber());
            int index = storeData.getRecords().indexOf(new GoblinStoreRecordData(goodId));
            if (index == -1) {
                LogUtils.error("该物品没有刷新在列表");
                playerController.sendWarn(WordFactory.STORE_GOODS_NOT_REFRESH);
                return;
            }
            GoblinStoreRecordData recordData = storeData.getRecords().get(index);
            if (recordData.isBuy) {
                LogUtils.error("该物品已经购买过");
                playerController.sendWarn(WordFactory.STORE_GOODS_HAS_BUY);
                return;
            }

            StableDataConfig config = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY, E_StableDataType.VIP_STORE_BUY_PRICE.getCode());
            if (playerController.getPlayer().getVipLevel() < config.intValue) {
                LogUtils.error("vip等级不足，当前：" + playerController.getPlayer().getVipLevel());
                playerController.sendWarn(WordFactory.VIP_LEVEL_NOT_ENOUGH, config.intValue);
                return;
            }
            //添加购买记录
            recordData.isBuy = true;
        } else {
            LogUtils.error("暂无此商店类型：" + request.getType());
            playerController.sendWarn(WordFactory.PARAM_ERROR, goods.price.id);
            return;
        }

        //增加兑换和发送给客户端
        bagInfo.addGoods(new GoodsData[]{new GoodsData(goods.goods.type, goods.goods.id, goods.goods.value * count)}, new GoodsData[]{new GoodsData(
                SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_ASSETS_VALUE, goods.price.id, goods.price.value * count)});

        SGPlayerProto.S2C_StoreBuyGoods.Builder response = SGPlayerProto.S2C_StoreBuyGoods.newBuilder();
        response.setType(request.getType());
        response.setGoodsId(goodId);
        response.setCount(count);
        playerController.sendMsg(code, response.build().toByteArray());
    }

    /**
     * 地精商店刷新
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void storeRefresh(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_StoreInitInfo request = null;
        try {
            request = SGPlayerProto.C2S_StoreInitInfo.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        LogUtils.debug("地精商店刷新请求参数: " + request.getType() + (request.getIsFresh() ? ", 刷新" : ", 拉取上次记录"));
        boolean isFresh = request.getIsFresh();

        if (request.getType() == SGCommonProto.E_STORE_TYPE.STORE_TYPE_GOBLIN) {
            BoonInfo boonInfo = playerController.getPlayer().getExtInfo(BoonInfo.class);
            StoreCacheData storeData = boonInfo.getGoblinStoreData().getStoreCache(request.getType().getNumber());
            LogUtils.debug("当前已经刷新的次数 :" + storeData.getHasRefreshTimes());
            if (isFresh && !storeData.isFreeTimesEnough()) {
                //免费次数不足，消耗物品
                StableDataConfig stableDataConfig = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY, E_StableDataType.GOBLIN_FRESH_TIMES.getCode());
                BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
                int goodsCount = bagInfo.getGoodsCount(stableDataConfig.goods[0].type, stableDataConfig.goods[0].id);
                if (goodsCount < stableDataConfig.goods[0].value) {
                    LogUtils.debug("商店刷新消耗 自己拥有:" + goodsCount + "     ,需要：" + stableDataConfig.goods[0].value);
                    playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, stableDataConfig.goods[0].id);
                    return;
                }
                //扣除资源
                bagInfo.addGoods(new GoodsData[0], stableDataConfig.goods);
            }

            //获取符合条件的物品
            List<SGCommonProto.StoreGoods> newGoods = getGoods(playerController, isFresh, storeData, request.getType());
            SGPlayerProto.S2C_StoreInitInfo.Builder response = SGPlayerProto.S2C_StoreInitInfo.newBuilder();
            response.setType(request.getType());
            response.addAllGoods(newGoods);
            response.setHasFreshTimes(storeData.getHasRefreshTimes());
            if (isFresh && storeData.isFreeTimesEnough()) {
                storeData.addRefreshTimes(DataFactory.currentTime);

                // 检测任务是否完成
                playerController.getPlayer().getExtInfo(TaskInfo.class).check(TaskFactory.TASK_TARAGET_GUBLIANSTORE, 1);
            }
            response.setFreeTimes(storeData.getRemindRefreshTimes());
            LogUtils.debug("返回给客户端竞技场商店初始化信息 ： " + response.toString());
            //返回给客户端
            playerController.sendMsg(code, response.build().toByteArray());

        } else if (request.getType() == SGCommonProto.E_STORE_TYPE.STORE_TYPE_ARENA) {
            BoonInfo boonInfo = playerController.getPlayer().getExtInfo(BoonInfo.class);
            StoreCacheData storeData = boonInfo.getGoblinStoreData().getStoreCache(request.getType().getNumber());
            if (isFresh) {
                //免费次数不足，消耗物品
                StableDataConfig stableDataConfig = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY, E_StableDataType.ARENA_BUY_PRICE.getCode());
                BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
                int goodsCount = bagInfo.getGoodsCount(stableDataConfig.goods[0].type, stableDataConfig.goods[0].id);
                if (goodsCount < stableDataConfig.goods[0].value) {
                    LogUtils.debug("商店刷新消耗 自己拥有:" + goodsCount + "     ,需要：" + stableDataConfig.goods[0].value);
                    playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, stableDataConfig.goods[0].id);
                    return;
                }
                //扣除资源
                storeData.addRefreshTimes(DataFactory.currentTime);
                bagInfo.addGoods(new GoodsData[0], stableDataConfig.goods);
            }

            //获取符合条件的物品
            List<SGCommonProto.StoreGoods> newGoods = getGoods(playerController, isFresh, storeData, request.getType());
            SGPlayerProto.S2C_StoreInitInfo.Builder response = SGPlayerProto.S2C_StoreInitInfo.newBuilder();
            response.setType(request.getType());
            response.addAllGoods(newGoods);
            response.setHasFreshTimes(storeData.getHasRefreshTimes());
            LogUtils.debug("返回给客户端竞技场商店初始化信息 ： " + response.toString());
            //返回给客户端
            playerController.sendMsg(code, response.build().toByteArray());
        } else if (request.getType() == SGCommonProto.E_STORE_TYPE.STORE_TYPE_EXPEDITION) {
            BoonInfo boonInfo = playerController.getPlayer().getExtInfo(BoonInfo.class);
            StoreCacheData storeData = boonInfo.getGoblinStoreData().getStoreCache(request.getType().getNumber());
            if (isFresh) {
                if (!storeData.isFreeTimesEnough()) {
                    LogUtils.debug("商店刷新次数不足，已经刷新：" + storeData.getHasRefreshTimes());
                    playerController.sendWarn(WordFactory.EXPEDITION_STORE_FRESH_TIMES_NOT_ENOUGH);
                    return;
                }
                //免费次数不足，消耗物品
                StableDataConfig stableDataConfig = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY, E_StableDataType.EXPEDITION_BUY_PRICE.getCode());
                BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
                int goodsCount = bagInfo.getGoodsCount(stableDataConfig.goods[0].type, stableDataConfig.goods[0].id);
                if (goodsCount < stableDataConfig.goods[0].value) {
                    LogUtils.debug("商店刷新消耗 自己拥有:" + goodsCount + "     ,需要：" + stableDataConfig.goods[0].value);
                    playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, stableDataConfig.goods[0].id);
                    return;
                }
                //扣除资源
                storeData.addRefreshTimes(DataFactory.currentTime);
                bagInfo.addGoods(new GoodsData[0], stableDataConfig.goods);
            }

            //获取符合条件的物品
            List<SGCommonProto.StoreGoods> newGoods = getGoods(playerController, isFresh, storeData, request.getType());
            SGPlayerProto.S2C_StoreInitInfo.Builder response = SGPlayerProto.S2C_StoreInitInfo.newBuilder();
            response.setType(request.getType());
            response.addAllGoods(newGoods);
            response.setHasFreshTimes(storeData.getHasRefreshTimes());
            LogUtils.debug("返回给客户端竞技场商店初始化信息 ： " + response.toString());
            //返回给客户端
            playerController.sendMsg(code, response.build().toByteArray());
        } else if (request.getType() == SGCommonProto.E_STORE_TYPE.STORE_TYPE_DIAMOND) {
            BoonInfo boonInfo = playerController.getPlayer().getExtInfo(BoonInfo.class);
            StoreCacheData storeData = boonInfo.getGoblinStoreData().getStoreCache(request.getType().getNumber());
            if (isFresh) {
                //免费次数不足，消耗物品
                StableDataConfig stableDataConfig = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY, E_StableDataType.DIAMOND_BUY_PRICE.getCode());
                BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
                int goodsCount = bagInfo.getGoodsCount(stableDataConfig.goods[0].type, stableDataConfig.goods[0].id);
                if (goodsCount < stableDataConfig.goods[0].value) {
                    LogUtils.debug("商店刷新消耗 自己拥有:" + goodsCount + "     ,需要：" + stableDataConfig.goods[0].value);
                    playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, stableDataConfig.goods[0].id);
                    return;
                }
                //扣除资源
                storeData.addRefreshTimes(DataFactory.currentTime);
                bagInfo.addGoods(new GoodsData[0], stableDataConfig.goods);
            }

            //获取符合条件的物品
            List<SGCommonProto.StoreGoods> newGoods = getGoods(playerController, isFresh, storeData, request.getType());
            SGPlayerProto.S2C_StoreInitInfo.Builder response = SGPlayerProto.S2C_StoreInitInfo.newBuilder();
            response.setType(request.getType());
            response.addAllGoods(newGoods);
            response.setHasFreshTimes(storeData.getHasRefreshTimes());
            LogUtils.debug("返回给客户端竞技场商店初始化信息 ： " + response.toString());
            //返回给客户端
            playerController.sendMsg(code, response.build().toByteArray());
        } else if (request.getType() == SGCommonProto.E_STORE_TYPE.STORE_TYPE_VIP) {
            BoonInfo boonInfo = playerController.getPlayer().getExtInfo(BoonInfo.class);
            StoreCacheData storeData = boonInfo.getGoblinStoreData().getStoreCache(request.getType().getNumber());
            if (isFresh) {
                //免费次数不足，消耗物品
                StableDataConfig stableDataConfig = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY, E_StableDataType.VIP_STORE_BUY_PRICE.getCode());
                BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
                int goodsCount = bagInfo.getGoodsCount(stableDataConfig.goods[0].type, stableDataConfig.goods[0].id);
                if (goodsCount < stableDataConfig.goods[0].value) {
                    LogUtils.debug("商店刷新消耗 自己拥有:" + goodsCount + "     ,需要：" + stableDataConfig.goods[0].value);
                    playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, stableDataConfig.goods[0].id);
                    return;
                }
                //扣除资源
                storeData.addRefreshTimes(DataFactory.currentTime);
                bagInfo.addGoods(new GoodsData[0], stableDataConfig.goods);
            }

            //获取符合条件的物品
            List<SGCommonProto.StoreGoods> newGoods = getGoods(playerController, isFresh, storeData, request.getType());
            SGPlayerProto.S2C_StoreInitInfo.Builder response = SGPlayerProto.S2C_StoreInitInfo.newBuilder();
            response.setType(request.getType());
            response.addAllGoods(newGoods);
            response.setHasFreshTimes(storeData.getHasRefreshTimes());
            LogUtils.debug("返回给客户端竞技场商店初始化信息 ： " + response.toString());
            //返回给客户端
            playerController.sendMsg(code, response.build().toByteArray());
        } else {
            LogUtils.error("暂无此商店类型：" + request.getType());
        }

    }

    /**
     * 获取新刷新的物品
     */
    private List<SGCommonProto.StoreGoods> getGoods(PlayerController playerController, boolean isFresh, StoreCacheData storeData, SGCommonProto.E_STORE_TYPE storeType) {

        List<SGCommonProto.StoreGoods> storeGoodsList = new ArrayList<>();
        BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
        SGCommonProto.StoreGoods.Builder storeGoods;
        int lv = playerController.getPlayer().getLv();
        if (storeType == SGCommonProto.E_STORE_TYPE.STORE_TYPE_GOBLIN) {
            if (isFresh || storeData.getRecords().size() == 0) {//刷新或者没有缓存过
                storeData.getRecords().clear();

                List<GoblinStoreConfig> allGoods = new ArrayList<>();
                allGoods.addAll(StoreManager.getInstance().getStoreGoods(storeType.getNumber(),
                        E_StoreGoodGroup.ABOVE_POSITION.getCode(), 2, lv));

                allGoods.addAll(StoreManager.getInstance().getStoreGoods(storeType.getNumber(),
                        E_StoreGoodGroup.BACK_POSITION.getCode(), 4, lv));
                for (GoblinStoreConfig goods : allGoods) {
                    storeData.getRecords().add(new GoblinStoreRecordData(goods.getId()));
                    storeGoods = SGCommonProto.StoreGoods.newBuilder();
                    storeGoods.setGoodsId(goods.id);
                    //碎片 属于道具 并且是碎片 道具类型4表示碎片
                    if (goods.goods.type == SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_PROPS_VALUE) {
                        PropConfig propConfig = DataFactory.getInstance().getGameObject(DataFactory.PROP_KEY, goods.goods.id);
                        if (propConfig != null
                                && propConfig.type == ConstantFactory.PROP_TYPE_CARD_SYN) {
                            getGoodsCompareBagParam(bagInfo, storeGoods, goods);
                        }
                    }
                    storeGoodsList.add(storeGoods.build());
                }
            } else {
                List<GoblinStoreRecordData> records = storeData.getRecords();
                for (GoblinStoreRecordData data : records) {
                    storeGoods = SGCommonProto.StoreGoods.newBuilder();
                    storeGoods.setGoodsId(data.goodsId);
                    storeGoods.setIsBuy(data.isBuy);
                    GoblinStoreConfig store = DataFactory.getInstance().getGameObject(DataFactory.GOBLIN_STORE_KEY, data.goodsId);
                    if (store == null) {
                        LogUtils.error("根据商品id获取商品配置错误");
                        return storeGoodsList;
                    }
                    if (store.goods.type ==
                            SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_PROPS_VALUE) {
                        //当为碎片类型需要查询背包获取已有，剩余和宿命上阵信息
                        PropConfig propConfig = DataFactory.getInstance().getGameObject(DataFactory.PROP_KEY, store.goods.id);
                        if (propConfig != null
                                && propConfig.type == ConstantFactory.PROP_TYPE_CARD_SYN) {
                            getGoodsCompareBagParam(bagInfo, storeGoods, store);
                        }
                    }
                    storeGoodsList.add(storeGoods.build());
                }
            }
        } else if (storeType == SGCommonProto.E_STORE_TYPE.STORE_TYPE_ARENA) {
            if (isFresh || storeData.getRecords().size() == 0) {//刷新或者没有缓存过
                storeData.getRecords().clear();

                List<GoblinStoreConfig> allGoods = new ArrayList<>();
                allGoods.addAll(StoreManager.getInstance().getStoreGoods(storeType.getNumber(),
                        E_StoreGoodGroup.BACK_POSITION.getCode(), 3, lv));

                allGoods.addAll(StoreManager.getInstance().getStoreGoods(storeType.getNumber(),
                        E_StoreGoodGroup.ABOVE_POSITION.getCode(), 5, lv));
                for (GoblinStoreConfig store : allGoods) {
                    storeData.getRecords().add(new GoblinStoreRecordData(store.getId()));
                    storeGoods = SGCommonProto.StoreGoods.newBuilder();
                    storeGoods.setGoodsId(store.id);
                    if (store.group == E_StoreGoodGroup.BACK_POSITION.getCode()) {

                        //当为碎片类型需要查询背包获取已有，剩余和宿命上阵信息
                        PropConfig propConfig = DataFactory.getInstance().getGameObject(DataFactory.PROP_KEY, store.goods.id);
                        if (propConfig != null
                                && propConfig.type == ConstantFactory.PROP_TYPE_CARD_SYN) {
                            getGoodsCompareBagParam(bagInfo, storeGoods, store);
                        }
                        //getGoodsCompareBagParam(bagInfo, storeGoods, store);
                    }
                    storeGoodsList.add(storeGoods.build());
                }
            } else {
                List<GoblinStoreRecordData> records = storeData.getRecords();
                for (GoblinStoreRecordData data : records) {
                    storeGoods = SGCommonProto.StoreGoods.newBuilder();
                    storeGoods.setGoodsId(data.goodsId);
                    storeGoods.setIsBuy(data.isBuy);
                    GoblinStoreConfig store = DataFactory.getInstance().getGameObject(DataFactory.GOBLIN_STORE_KEY, data.goodsId);
                    if (store == null) {
                        LogUtils.error("根据商品id获取商品配置错误");
                        return storeGoodsList;
                    }

                    if (store.goods.type ==
                            SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_PROPS_VALUE) {
                        //当为碎片类型需要查询背包获取已有，剩余和宿命上阵信息
                        PropConfig propConfig = DataFactory.getInstance().getGameObject(DataFactory.PROP_KEY, store.goods.id);
                        if (propConfig != null
                                && propConfig.type == ConstantFactory.PROP_TYPE_CARD_SYN) {
                            getGoodsCompareBagParam(bagInfo, storeGoods, store);
                        }
                    }
                    storeGoodsList.add(storeGoods.build());
                }
            }
        } else if (storeType == SGCommonProto.E_STORE_TYPE.STORE_TYPE_EXPEDITION) {
            if (isFresh || storeData.getRecords().size() == 0) {//刷新或者没有缓存过
                storeData.getRecords().clear();

                List<GoblinStoreConfig> allGoods = new ArrayList<>();
                allGoods.addAll(StoreManager.getInstance().getStoreGoods(storeType.getNumber(),
                        E_StoreGoodGroup.BACK_POSITION.getCode(), 3, lv));

                allGoods.addAll(StoreManager.getInstance().getStoreGoods(storeType.getNumber(),
                        E_StoreGoodGroup.ABOVE_POSITION.getCode(), 5, lv));
                for (GoblinStoreConfig store : allGoods) {
                    storeData.getRecords().add(new GoblinStoreRecordData(store.getId()));
                    storeGoods = SGCommonProto.StoreGoods.newBuilder();
                    storeGoods.setGoodsId(store.id);
                    if (store.goods.type ==
                            SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_PROPS_VALUE) {
                        //当为碎片类型需要查询背包获取已有，剩余和宿命上阵信息
                        PropConfig propConfig = DataFactory.getInstance().getGameObject(DataFactory.PROP_KEY, store.goods.id);
                        if (propConfig != null
                                && propConfig.type == ConstantFactory.PROP_TYPE_CARD_SYN) {
                            getGoodsCompareBagParam(bagInfo, storeGoods, store);
                        }
                    }
                    storeGoodsList.add(storeGoods.build());
                }
            } else {
                List<GoblinStoreRecordData> records = storeData.getRecords();
                for (GoblinStoreRecordData data : records) {
                    storeGoods = SGCommonProto.StoreGoods.newBuilder();
                    storeGoods.setGoodsId(data.goodsId);
                    storeGoods.setIsBuy(data.isBuy);
                    GoblinStoreConfig store = DataFactory.getInstance().getGameObject(DataFactory.GOBLIN_STORE_KEY, data.goodsId);
                    if (store == null) {
                        LogUtils.error("根据商品id获取商品配置错误");
                        return storeGoodsList;
                    }

                    if (store.goods.type ==
                            SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_PROPS_VALUE) {
                        //当为碎片类型需要查询背包获取已有，剩余和宿命上阵信息
                        PropConfig propConfig = DataFactory.getInstance().getGameObject(DataFactory.PROP_KEY, store.goods.id);
                        if (propConfig != null
                                && propConfig.type == ConstantFactory.PROP_TYPE_CARD_SYN) {
                            getGoodsCompareBagParam(bagInfo, storeGoods, store);
                        }
                    }

                    storeGoodsList.add(storeGoods.build());
                }
            }
        } else if (storeType == SGCommonProto.E_STORE_TYPE.STORE_TYPE_DIAMOND) {
            if (isFresh || storeData.getRecords().size() == 0) {//刷新或者没有缓存过
                storeData.getRecords().clear();

                List<GoblinStoreConfig> allGoods = new ArrayList<>();
                allGoods.addAll(StoreManager.getInstance().getStoreGoods(storeType.getNumber(),
                        E_StoreGoodGroup.ABOVE_POSITION.getCode(), 3, lv));

                allGoods.addAll(StoreManager.getInstance().getStoreGoods(storeType.getNumber(),
                        E_StoreGoodGroup.BACK_POSITION.getCode(), 5, lv));
                for (GoblinStoreConfig store : allGoods) {
                    storeData.getRecords().add(new GoblinStoreRecordData(store.getId()));
                    storeGoods = SGCommonProto.StoreGoods.newBuilder();
                    storeGoods.setGoodsId(store.id);

                    if (store.goods.type ==
                            SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_PROPS_VALUE) {
                        //当为碎片类型需要查询背包获取已有，剩余和宿命上阵信息
                        PropConfig propConfig = DataFactory.getInstance().getGameObject(DataFactory.PROP_KEY, store.goods.id);
                        if (propConfig != null
                                && propConfig.type == ConstantFactory.PROP_TYPE_CARD_SYN) {
                            getGoodsCompareBagParam(bagInfo, storeGoods, store);
                        }
                    }
                    storeGoodsList.add(storeGoods.build());
                }
            } else {
                List<GoblinStoreRecordData> records = storeData.getRecords();
                for (GoblinStoreRecordData data : records) {
                    storeGoods = SGCommonProto.StoreGoods.newBuilder();
                    storeGoods.setGoodsId(data.goodsId);
                    storeGoods.setIsBuy(data.isBuy);
                    GoblinStoreConfig store = DataFactory.getInstance().getGameObject(DataFactory.GOBLIN_STORE_KEY, data.goodsId);
                    if (store == null) {
                        LogUtils.error("根据商品id获取商品配置错误");
                        return storeGoodsList;
                    }

                    if (store.goods.type ==
                            SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_PROPS_VALUE) {
                        //当为碎片类型需要查询背包获取已有，剩余和宿命上阵信息
                        PropConfig propConfig = DataFactory.getInstance().getGameObject(DataFactory.PROP_KEY, store.goods.id);
                        if (propConfig != null
                                && propConfig.type == ConstantFactory.PROP_TYPE_CARD_SYN) {
                            getGoodsCompareBagParam(bagInfo, storeGoods, store);
                        }
                    }

                    storeGoodsList.add(storeGoods.build());
                }
            }
        } else if (storeType == SGCommonProto.E_STORE_TYPE.STORE_TYPE_VIP) {
            if (isFresh || storeData.getRecords().size() == 0) {//刷新或者没有缓存过
                storeData.getRecords().clear();

                List<GoblinStoreConfig> allGoods = new ArrayList<>();
                allGoods.addAll(StoreManager.getInstance().getStoreGoods(storeType.getNumber(),
                        E_StoreGoodGroup.ABOVE_POSITION.getCode(), 3, lv));

                allGoods.addAll(StoreManager.getInstance().getStoreGoods(storeType.getNumber(),
                        E_StoreGoodGroup.BACK_POSITION.getCode(), 5, lv));
                for (GoblinStoreConfig store : allGoods) {
                    storeData.getRecords().add(new GoblinStoreRecordData(store.getId()));
                    storeGoods = SGCommonProto.StoreGoods.newBuilder();
                    storeGoods.setGoodsId(store.id);
                    if (store.goods.type ==
                            SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_PROPS_VALUE) {
                        //当为碎片类型需要查询背包获取已有，剩余和宿命上阵信息
                        PropConfig propConfig = DataFactory.getInstance().getGameObject(DataFactory.PROP_KEY, store.goods.id);
                        if (propConfig != null
                                && propConfig.type == ConstantFactory.PROP_TYPE_CARD_SYN) {
                            getGoodsCompareBagParam(bagInfo, storeGoods, store);
                        }
                    }
                    storeGoodsList.add(storeGoods.build());
                }
            } else {
                List<GoblinStoreRecordData> records = storeData.getRecords();
                for (GoblinStoreRecordData data : records) {
                    storeGoods = SGCommonProto.StoreGoods.newBuilder();
                    storeGoods.setGoodsId(data.goodsId);
                    storeGoods.setIsBuy(data.isBuy);
                    GoblinStoreConfig store = DataFactory.getInstance().getGameObject(DataFactory.GOBLIN_STORE_KEY, data.goodsId);
                    if (store == null) {
                        LogUtils.error("根据商品id获取商品配置错误");
                        return storeGoodsList;
                    }

                    if (store.goods.type ==
                            SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_PROPS_VALUE) {
                        //当为碎片类型需要查询背包获取已有，剩余和宿命上阵信息
                        PropConfig propConfig = DataFactory.getInstance().getGameObject(DataFactory.PROP_KEY, store.goods.id);
                        if (propConfig != null
                                && propConfig.type == ConstantFactory.PROP_TYPE_CARD_SYN) {
                            getGoodsCompareBagParam(bagInfo, storeGoods, store);
                        }
                    }

                    storeGoodsList.add(storeGoods.build());
                }
            }
        }

        return storeGoodsList;
    }

    /**
     * 获取商品和背包的比较
     *
     * @param bagInfo
     * @param storeGoods
     * @param goods
     */
    private void getGoodsCompareBagParam(BagInfo bagInfo, SGCommonProto.StoreGoods.Builder storeGoods, GoblinStoreConfig goods) {
        //获取碎片数量
        int num = bagInfo.getPropCount(goods.goods.id);
        storeGoods.setHasCount(num);
        //查询下一级所需的数量
        CardDB card = bagInfo.getCardData().getCard(goods.goods.id);
        if (card != null) { // 自己已经拥有这张卡片
            int nextLevel = 0;
            ll:
            for (int i = 1; ; i++) { // 找到第一个需要碎片的等级
                nextLevel = card.star + i;
                CardStarConfig cardStarConfig = DataFactory.getInstance().getGameObject(DataFactory.CARD_STAR_KEY, nextLevel);
                if (cardStarConfig != null) {
                    for (GoodsData data : cardStarConfig.needDebris) {
                        if (data.type == card.getConfig().quality && data.value != 0) {
                            storeGoods.setNeedCount(data.value);
                            break ll;
                        }
                    }
                } else {
                    break;
                }
            }


        } else { // 没有卡，合成需要的数量
            //TODO
            CardConfig cardConfig = DataFactory.getInstance().getGameObject(DataFactory.CARD_KEY, goods.goods.id);
            if (cardConfig != null) {
                storeGoods.setNeedCount(cardConfig.transformation);
            } else {
                LogUtils.error("BoonMsgChannel error 卡片找不到： " + goods.goods.id);
            }
        }
        // 查询已上阵标签和宿命
        SGCommonProto.E_STORE_LABEL label = null;
        if (bagInfo.isBattleCard(goods.goods.id)) {
            label = SGCommonProto.E_STORE_LABEL.LABEL_ALREADY_BATTLE;
        } else if (bagInfo.hasFateLabel(goods.goods.id)) {
            label = SGCommonProto.E_STORE_LABEL.LABEL_FATE;
        }
        if (label != null) {
            storeGoods.setLabel(label);
        }
//        while (it.hasNext()) {
//            Map.Entry<Integer, List<Integer>> entry = it.next();
//            List<Integer> cardList = entry.getValue();
//            if(cardList.contains(goods.goods.id)){
//                label = SGCommonProto.E_STORE_LABEL.LABEL_ALREADY_BATTLE;
//                break;
//            }
//            ll:
//            for(Integer id : cardList){//id 上阵卡组的id
//                for(CardFate fate : fateList){
//                    if(fate.isCardHasFate(goods.goods.id, id)){
//                        label = SGCommonProto.E_STORE_LABEL.LABEL_FATE;
//                        break ll;
//                    }
//
//                }
//            }
//        }

    }

    /**
     * 竞拍
     *
     * @param playerController
     * @param code
     * @param data
     */
    synchronized public void buyAuction(PlayerController playerController, int code, byte[] data) {
        SGPlayerProto.C2S_WorldAuctionBuy request = null;
        try {
            request = SGPlayerProto.C2S_WorldAuctionBuy.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            //当数据为空的时候 应该return
            return;
        }
        //id
        int auctionShelveId = request.getAuctionShelveId();
        WorldAuctionData worldAuctionData = GameServer.getInstance().getWorldAuctionData();
        WorldAuctionBean auctionBean = worldAuctionData.getRecord(auctionShelveId);
        SGPlayerProto.S2C_WorldAuctionBuy.Builder response = SGPlayerProto.S2C_WorldAuctionBuy.newBuilder();
        response.setAuctionShelveId(auctionShelveId);
        if (auctionBean == null ||
                auctionBean.getState() == E_AuctionStatus.END_THE_AUCTION.getCode()) {
            //拍卖已经结束
            LogUtils.error("拍卖已经结束");
            response.setIsSuccess(false);
            response.setIsEnd(true);
            response.setAuctionReward(playerController.getPlayer().getBonusData().getAuctionReward());
            playerController.sendMsg(code, response.build().toByteArray());
            playerController.sendWarn(WordFactory.AUCTION_ALREADY_OVER);
            return;
        }
        response.setIsEnd(false);
        AuctionConfig auctionConfig = WorldAuctionData.getAuctionConfig(auctionBean.getAuctionConfigId());
        if (auctionConfig == null) {
            //价格过低
            LogUtils.error("拍卖config出错");
            playerController.sendWarn(WordFactory.SERVER_DATA_ERROR);
            return;
        }
        //出价
        int buyPrice = request.getBuyPrice();
        if ((auctionBean.getCurrentPrice() + auctionConfig.addPrice) > buyPrice
                && auctionConfig.highestPrice > buyPrice) {
            //价格过低
            //小于最低价 并且小于一口价
            LogUtils.error("竞拍出价过低");
            playerController.sendWarn(WordFactory.AUCTION_LOW_BID);
            response.setIsSuccess(false);
            response.setAuctionShelveId(auctionShelveId);
            response.setCurrentPrice(auctionBean.getCurrentPrice());
            response.setAuctionReward(playerController.getPlayer().getBonusData().getAuctionReward());
            playerController.sendMsg(code, response.build().toByteArray());
            return;
        }
        //判断玩家出的价格是否是该出的价格 如果不是需要二次确认
        if ((auctionBean.getCurrentPrice() + auctionConfig.addPrice) != buyPrice
                && buyPrice != auctionConfig.highestPrice) {
            //通知客户端这个价格计算不正确 修正价格
            LogUtils.debug("竞拍价格不正确,修正价格");
            response.setIsSuccess(false);
            response.setAuctionShelveId(auctionShelveId);
            //设置价格
            response.setCurrentPrice(auctionBean.getCurrentPrice());
            response.setAuctionReward(playerController.getPlayer().getBonusData().getAuctionReward());
            playerController.sendMsg(code, response.build().toByteArray());
            return;
        }

        BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
        //判断玩家手中的价格是否够用
        if (bagInfo.getAsset(auctionConfig.price.id) < buyPrice) {
            //资源不够
            LogUtils.debug("竞拍资源数量不足");
            playerController.sendWarn(WordFactory.ASSET_NOT_ENOUGH, auctionConfig.price.id);
            return;
        }

        if (auctionBean.getCurrentPlayer() != null && auctionBean.getCurrentPlayer().trim().length() > 0) {
            TwoTuple<Player, PlayerController> towtule = GameServer.getInstance().getWorldManager().getPlayerResult(auctionBean.getCurrentPlayer());
            Player lastPlayer = towtule.getFirst();
            //返回拍卖失败玩家的资源
//            BagInfo lastBag = lastPlayer.getExtInfo(BagInfo.class);
//            lastBag.addGoods(new GoodsData(auctionConfig.price.type,
//                            auctionConfig.price.id
//                            , auctionBean.getCurrentPrice()),true);

            //邮件通知上一个玩家竞拍失败
            MailInfo mailInfo = lastPlayer.getExtInfo(MailInfo.class);
            MailConfig mailConfig = DataFactory.getInstance().getGameObject(DataFactory.MAIL_MODEL_KEY, E_MailModelType.AUCTION_FAIL_GOODS.getCode());
            AuctionRecord record = lastPlayer.getBonusData().getRecords().get(auctionShelveId);
            //{0}{1} 拍卖时间  拍卖品名称
            MailDB mailDB = new MailDB(mailConfig.title, MessageFormat.format(mailConfig.content, new Date(record.getAuctionTime()), getGoodName(auctionConfig.good.type, auctionConfig.good.id)), new ArrayList<>());
            mailDB.addAttach(new GoodsData(auctionConfig.price.type,
                    auctionConfig.price.id
                    , auctionBean.getCurrentPrice()));
            mailInfo.addMail(SGCommonProto.E_MAIL_TYPE.MAIL_TYPE_SYSTEM_VALUE, mailDB);
            //设置上一个玩家的竞拍记录为false
            lastPlayer.getBonusData().getRecords().get(auctionShelveId).setSuccess(false);
            //刷新上一个玩家的列表
            if (towtule.getSecond() != null) {
                towtule.getSecond().sendMsg(SGMainProto.E_MSG_ID.MSGID_WorldAuctionChange_VALUE, getAuctionRecords(lastPlayer).build().toByteArray());
            } else {
                //GameServer.getInstance().savePlayer(lastPlayer);
                GameServer.getInstance().savePlayerSync(lastPlayer, false, MailInfo.class);
            }
        }
        auctionBean.setCurrentPlayer(playerController.getPlayer().getObjectIndex());
        //设置当前玩家的记录
        playerController.getPlayer().getBonusData().getRecords().put(auctionShelveId, new AuctionRecord(auctionShelveId, true));
        if (!auctionBean.getAuctionList().contains(new String(playerController.getObjectIndex()))) {
            //如果list中不存在该用户加入到list
            auctionBean.getAuctionList().add(new String(playerController.getObjectIndex()));
        }
        //如果购买价格 已达最大值
        if (buyPrice == auctionConfig.highestPrice) {
            //扣除玩家资源 highestPrice
            bagInfo.addGoods(new GoodsData[]{}, new GoodsData[]{new GoodsData(
                    auctionConfig.price.type, auctionConfig.price.id, auctionConfig.highestPrice
            )});
            //设置当前的currentPrice 为highestPrice
            auctionBean.setCurrentPrice(auctionConfig.highestPrice);
            //成功竞拍到商品 并且保存
            Map<String, AuctionRewardPlayer> playerMap = new HashMap<>();
            WorldManager manager = new WorldManager();
            auctionSuccess(auctionBean, true, playerMap);
            manager.auctionPlayerUpdate(playerMap);
            LogUtils.debug(playerController.getPlayer().getAccount() + "一口价竞拍商品成功！价格为" + auctionConfig.highestPrice);
            //做io操作存储到数据库
            manager.saveDiamonds(playerController.getObjectIndex(), -auctionConfig.highestPrice);
        } else {
            //扣除玩家的资源
            bagInfo.addGoods(new GoodsData[]{}, new GoodsData[]{new GoodsData(
                    auctionConfig.price.type, auctionConfig.price.id, buyPrice
            )}, false);
            //设置当前的currentPrice 为highestPrice
            auctionBean.setCurrentPrice(buyPrice);
            LogUtils.debug(playerController.getPlayer().getAccount() + "参与竞拍成功！价格为" + buyPrice);
        }

        //返回竞拍成功 并且给出当前的价格
        response.setIsSuccess(true);
        response.setAuctionShelveId(auctionShelveId);
        response.setCurrentPrice(auctionBean.getCurrentPrice());
        response.setAuctionReward(playerController.getPlayer().getBonusData().getAuctionReward());
        playerController.sendMsg(code, response.build().toByteArray());
        //通知玩家刷新竞拍列表
        playerController.sendMsg(SGMainProto.E_MSG_ID.MSGID_WorldAuctionChange_VALUE, getAuctionRecords(playerController.getPlayer()).build().toByteArray());
    }

    /**
     * 初始化拍卖行页面
     *
     * @param playerController
     * @param code
     */
    public void auctionValue(PlayerController playerController, int code) {
        SGPlayerProto.S2C_WorldAuctionInit.Builder response = SGPlayerProto.S2C_WorldAuctionInit.newBuilder();
        //当前拍卖物品的list
        WorldAuctionData worldAuctionData = WorldInfoFactory.getInstance().getWorldAuctionData();
        AuctionConfig auctionConfig;
        WorldAuctionBean bean;
        for (Map.Entry<Integer, WorldAuctionBean> entry : worldAuctionData.getAuctionMap().entrySet()) {
            SGCommonProto.E_AUCTION_STATUS status = SGCommonProto.E_AUCTION_STATUS.AUCTION_STATUS_UNKNOW;
            bean = entry.getValue();
            if (bean.getState() == E_AuctionStatus.INT_THE_AUCTION.getCode()) {
                //判断自己是否参与过竞拍
                for (String value : bean.getAuctionList()) {
                    if (value.equals(playerController.getObjectIndex())) {
                        //如果自己参与过拍卖 获取状态
                        status = bean.getCurrentPlayer().equals(playerController.getObjectIndex()) ? SGCommonProto.E_AUCTION_STATUS.AUCTION_STATUS_HIEHEST
                                : SGCommonProto.E_AUCTION_STATUS.AUCTION_STATUS_LOWER;
                        break;
                    }
                }

                auctionConfig = WorldAuctionData.getAuctionConfig(bean.getAuctionConfigId());
                //获取配置信息
                response.addAuctionInfos(SGCommonProto.AuctionInfo.newBuilder()
                        .setAuctionConfigId(bean.getAuctionConfigId())
                        .setAuctionShelveId(bean.getId())
                        .setCurrentPrice(bean.getCurrentPrice())
                        .setDuration(bean.getStartTime() + auctionConfig.keepTime - DataFactory.currentTime)
                        .setStatus(status));
            }
        }

        //获取分红数量
        Integer auctionReward = playerController.getPlayer().getBonusData().getAuctionReward();
        response.setAuctionReward(auctionReward);
        //获取拍卖记录
        response.addAllAuctionRecords(getAuctionRecords(playerController.getPlayer()).getAuctionRecordsList());
        LogUtils.debug("获取拍卖商城初始化信息完成");

        playerController.sendMsg(code, response.build().toByteArray());
    }

    /**
     * 领取boss掉落物品出售后分红
     *
     * @param playerController
     * @param code
     */
    public void auctionReward(PlayerController playerController, int code) {
        //获取玩家本周充值金额
        //int weekRecharge = boonInfo.getBonusData().getWeeklyRechargeRmb();
        int weekRecharge = playerController.getPlayer().getRechargeData().getRechargeCount(E_QueryRechargeCountType.WEEKLY.getCode());
        //领取充值条件 默认取第一条数据吧
        StableDataConfig stableDataConfig = DataFactory.getInstance().getGameObject(DataFactory.STABLE_DATA_KEY, E_StableDataType.AUCTION_RECHARGE_DIAMOND.getCode());
        int minRecharge = stableDataConfig.intValue;
        if (weekRecharge < minRecharge) {
            //充值的不足
            LogUtils.debug("用户" + playerController.getPlayer().getName() + "本周充值不足");
            playerController.sendWarn(WordFactory.AUCTION_RECHARGE_NOT_ENOUGH_WEEK);
            return;
        }
        //判断可领取数量
        if (playerController.getPlayer().getBonusData().getAuctionReward() <= 0) {
            //无可领取的奖励
            LogUtils.debug("用户" + playerController.getPlayer().getName() + "拍卖行分红为0");
            playerController.sendWarn(WordFactory.AUCTION_REWARD_NOT_ENOUGH);
            return;
        }
        //将奖励增加到玩家的资源中 然后清空玩家的boss分红
        BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
        bagInfo.addAsset(ConfigFactory.ASSET_MONEY_KEY, playerController.getPlayer().getBonusData().getAuctionReward());
        playerController.getPlayer().getBonusData().setAuctionReward(0);
        //通知玩家领取成功
        SGPlayerProto.S2C_WorldGetAuctionWeeklyReward.Builder response = SGPlayerProto.S2C_WorldGetAuctionWeeklyReward.newBuilder();
        //领取成功不需要做返回值 会自动刷新用户的数据的
        playerController.sendMsg(code, response.build().toByteArray());
    }

    /**
     * 拍卖成功的方法
     *
     * @param auction
     * @param success true表示拍卖成功 false表示流拍
     */
    synchronized public void auctionSuccess(WorldAuctionBean auction, boolean success, Map<String, AuctionRewardPlayer> savePlayerMap) {
        if (success) {
            //邮件通知玩家领取物品
            sendMail(auction, savePlayerMap);
        }
        //流拍 不流拍 都设置结束
        auction.setState(E_AuctionStatus.END_THE_AUCTION.getCode());
        auction.setEndTime(DataFactory.currentTime);
        //获取所有参与拍卖的玩家通知他们拍卖记录的变化  这个只需要通知在线玩家
        PlayerController playerController;
        for (String playerIndex : auction.getAuctionList()) {
            playerController = GameServer.getInstance().getWorldManager().getPlayerController(playerIndex);
            if (playerController != null)
                playerController.sendMsg(SGMainProto.E_MSG_ID.MSGID_WorldAuctionChange_VALUE, getAuctionRecords(playerController.getPlayer()).build().toByteArray());
        }

        if (auction.getPlayerList().isEmpty()) {
            LogUtils.debug("参与分红的玩家数量为0 -> " + auction.getId());
            return;
        }
        int auctionReward = (int) Math.ceil(auction.getCurrentPrice() * ConstantFactory.AUCTION_BONUS_RATIO / auction.getPlayerList().size());
        AuctionRewardPlayer auctionRewardPlayer;
        for (String playerIndex : auction.getPlayerList()) {
            auctionRewardPlayer = savePlayerMap.get(playerIndex);
            if (auctionRewardPlayer == null) {
                //如果玩家不再map中
                auctionRewardPlayer = new AuctionRewardPlayer();
                savePlayerMap.put(playerIndex, auctionRewardPlayer);
            }
            //如果玩家在map中
            savePlayerMap.get(playerIndex).addTotalRewardMoney(auctionReward);
        }
//        if(savePlayers.size() > 0){
//            GameServer.getInstance().savePlayerList(savePlayers,false,BoonInfo.class);
//        }
    }

    /**
     * 获取拍卖记录
     *
     * @param player
     * @return
     */
    public SGPlayerProto.S2C_WorldAuctionChange.Builder getAuctionRecords(Player player) {
        SGPlayerProto.S2C_WorldAuctionChange.Builder change = SGPlayerProto.S2C_WorldAuctionChange.newBuilder();
        SGCommonProto.AuctionRecord.Builder auctionRecord = null;
        WorldAuctionBean bean;
        SGCommonProto.E_AUCTION_STATUS status;
        for (Map.Entry<Integer, AuctionRecord> entry : player.getBonusData().getRecords().entrySet()) {
            bean = WorldInfoFactory.getInstance().getWorldAuctionData().getAuctionMap().get(entry.getKey());
            if (bean == null) {
                continue;
            }
            //获取状态
            status = SGCommonProto.E_AUCTION_STATUS.AUCTION_STATUS_UNKNOW;
            if (bean.getState() == E_AuctionStatus.INT_THE_AUCTION.getCode()) {
                //拍卖中
                entry.getValue().setEnd(false);
                if (bean.getCurrentPlayer() == null) {
                    status = SGCommonProto.E_AUCTION_STATUS.AUCTION_STATUS_LOWER;
                    entry.getValue().setSuccess(false);
                } else if (bean.getCurrentPlayer().equals(player.getObjectIndex())) {
                    status = SGCommonProto.E_AUCTION_STATUS.AUCTION_STATUS_HIEHEST;
                    entry.getValue().setSuccess(true);
                } else {
                    status = SGCommonProto.E_AUCTION_STATUS.AUCTION_STATUS_LOWER;
                    entry.getValue().setSuccess(false);
                }
            } else {
                entry.getValue().setEnd(true);
                //拍卖结束
                if (bean.getCurrentPlayer().equals(player.getObjectIndex())) {
                    status = SGCommonProto.E_AUCTION_STATUS.AUCTION_STATUS_SUCCESS;
                    entry.getValue().setSuccess(true);
                } else {
                    status = SGCommonProto.E_AUCTION_STATUS.AUCTION_STATUS_FAIL;
                    entry.getValue().setSuccess(false);
                }
            }
            auctionRecord = SGCommonProto.AuctionRecord.newBuilder()
                    .setAuctionShelveId(entry.getValue().getAuctionBeanId())
                    .setAuctionConfigId(bean.getAuctionConfigId())
                    .setStatus(status);
            change.addAuctionRecords(auctionRecord);

        }
        return change;
    }

    /**
     * 初始化mall商店
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void initMallStore(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_MallInitInfo request = null;
        try {
            request = SGPlayerProto.C2S_MallInitInfo.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        MallData mallData = playerController.getPlayer().getMallData();
        SGPlayerProto.S2C_MallInitInfo.Builder response = SGPlayerProto.S2C_MallInitInfo.newBuilder();
        getBuyMallData(request, mallData, response);
        response.setMallType(request.getMallType());
        playerController.sendMsg(code, response.build().toByteArray());
    }


    /**
     * 购买商品mall
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void buyMallGoods(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_MallBuy request = null;
        try {
            request = SGPlayerProto.C2S_MallBuy.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        int goodId = request.getGoodsId();
        int count = request.getCount();
        count = count <= 0 ? 1 : count;
        MallConfig mallConfig = DataFactory.getInstance().getGameObject(DataFactory.MALL_STORE_KEY, goodId);
        if (mallConfig == null) {
            LogUtils.error("根据商品id获取商品配置错误" + goodId);
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        BagInfo bagInfo = playerController.getPlayer().getExtInfo(BagInfo.class);
        MallData mallData = playerController.getPlayer().getMallData();
        int hasCount = mallData.checkHasBuyCount(goodId);
        if (mallConfig.RestrictionAmount != 0) {
            //限购
            int needCount = hasCount + count;
            if (needCount > mallConfig.RestrictionAmount) {
                LogUtils.error("已达到购买上限 max:" + mallConfig.RestrictionAmount + ", needCount" + needCount);
                playerController.sendWarn(WordFactory.BUY_TIMES_TOUCH_MAX);
                return;
            }
        }

        if (mallConfig.minLevel > 0 && playerController.getPlayer().getVipLevel() < mallConfig.minLevel) {
            LogUtils.error("vip等级不足");
            playerController.sendWarn(WordFactory.VIP_LEVEL_NOT_ENOUGH, mallConfig.minLevel);
            return;
        }
        GoodsData[] priceAry = getPriceArry(mallConfig);
        int needPrice = getBuyNeedResources(count, hasCount, priceAry);

        if (bagInfo.getGoodsCount(priceAry[0].type, priceAry[0].id) < needPrice) {
            //TODO 资源不足
            LogUtils.debug("购买的价格id-->" + priceAry[0].id + " 超出价格：" + needPrice + ", 自己拥有:" + bagInfo.getAsset(priceAry[0].id));
            playerController.sendWarn(WordFactory.STORE_GOODS_MONEY_NOT_ENOUGH, priceAry[0].id);
            return;
        }
        //将购买的数量添加
        mallData.addAuctionData(goodId, count);
        //增加兑换和发送给客户端
        bagInfo.addGoods(new GoodsData[]{new GoodsData(mallConfig.goods.type, mallConfig.goods.id, mallConfig.goods.value * count)}, new GoodsData[]{new GoodsData(
                priceAry[0].type, priceAry[0].id, needPrice)});

    	// 检测任务是否完成
        playerController.getPlayer().getExtInfo(TaskInfo.class).check(TaskFactory.TASK_TARAGET_EVERYDAY_SHOP_BUY, count);

        SGPlayerProto.S2C_MallBuy.Builder response = SGPlayerProto.S2C_MallBuy.newBuilder();
        response.setGoodsId(goodId);
        response.setTotalBuyCount(mallData.checkHasBuyCount(goodId));
        playerController.sendMsg(code, response.build().toByteArray());
    }

    /**
     * 获取需要的价格数组
     *
     * @param mallConfig
     * @return
     */
    private GoodsData[] getPriceArry(MallConfig mallConfig) {
        GoodsData[] priceAry;
        if (mallConfig.discountPrice.length != 0) {//获取是否有折扣价
            priceAry = mallConfig.discountPrice;//折扣价
        } else {
            priceAry = mallConfig.originalPrice;//原价
        }
        return priceAry;
    }

    /**
     * 获取购买需要的资源
     *
     * @param count
     * @param hasCount
     * @param priceAry
     * @return
     */
    private int getBuyNeedResources(int count, int hasCount, GoodsData[] priceAry) {
        int needPrice = 0;
        for (int i = hasCount; i < count + hasCount; i++) {
            int index = Math.min(i, priceAry.length - 1);
            needPrice += priceAry[index].value;
        }
        return needPrice;
    }

    /**
     * 获取我购买的物品信息
     *
     * @param request
     * @param mallData
     * @param response
     */
    private void getBuyMallData(SGPlayerProto.C2S_MallInitInfo request, MallData mallData, SGPlayerProto.S2C_MallInitInfo.Builder response) {
        SGCommonProto.CommonObject.Builder buyGoods;
        for (Map.Entry<Integer, Integer> entry : mallData.getBuyGoodsMap().entrySet()) {
            MallConfig mallConfig = DataFactory.getInstance().getGameObject(DataFactory.MALL_STORE_KEY, entry.getKey());
            if (mallConfig != null) {
                buyGoods = SGCommonProto.CommonObject.newBuilder();
                if (mallConfig.mallType == request.getMallType().getNumber()) {
                    buyGoods.setId(entry.getKey());
                    buyGoods.setValue(entry.getValue());
                    response.addGoodsInfo(buyGoods);
                }
            }

        }
    }

    /**
     * 分享成功回调
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void shareSuccess(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_ShareSuccess request = null;
        try {
            request = SGPlayerProto.C2S_ShareSuccess.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }

        if (request == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }
        int shareId = request.getShareId();
        /**
         * 1.验证该分享内容是否处于用户正在进行的分享任务
         * 2.验证分享的状态是否是否是处于不可分享或者是可分享
         * 3.不可分享的验证是否达成条件
         * 4.修改状态为待领奖
         */
        ShareData shareData = playerController.getPlayer().getShareData();
        ShareBean shareBean = shareData.getShareBeanMap().get(shareId);
        if (shareBean == null) {
            playerController.sendWarn(WordFactory.SHARE_NOT_IN_PROGRESS);
            return;
        }

        //验证状态
        if (shareBean.getStateCode() != SGCommonProto.E_SHARE_STATE.SHARE_STATE_CANNOTSHARE_VALUE
                && shareBean.getStateCode() != SGCommonProto.E_SHARE_STATE.SHARE_STATE_CANSHARE_VALUE) {
            playerController.sendWarn(WordFactory.SHARE_STATE_ERROR);
            return;
        }

        ShareConfig config = DataFactory.getInstance().getGameObject(DataFactory.SHARE_KEY, shareId);
        if (config == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        if (shareBean.getStateCode() == SGCommonProto.E_SHARE_STATE.SHARE_STATE_CANNOTSHARE_VALUE) {
            //验证是达成条件
            if (!shareData.isCanShare(shareId, config)) {
                playerController.sendWarn(WordFactory.SHARE_STATE_ERROR);
                return;
            }
        }
        shareBean.setStateCode(SGCommonProto.E_SHARE_STATE.SHARE_STATE_CANRECEIVEREWARD_VALUE);
        SGPlayerProto.S2C_ShareSuccess.Builder response = SGPlayerProto.S2C_ShareSuccess.newBuilder();
        response.setResult(true);
        response.setShareObj(shareData.getShareObject(shareBean));
        playerController.sendMsg(code, response.build().toByteArray());
    }

    /**
     * 分享后领奖
     *
     * @param playerController
     * @param data
     * @param code
     */
    private void shareReceive(PlayerController playerController, byte[] data, int code) {
        SGPlayerProto.C2S_ShareReceive request = null;
        try {
            request = SGPlayerProto.C2S_ShareReceive.parseFrom(data);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }

        int shareId = request.getShareId();
        ShareData shareData = playerController.getPlayer().getShareData();
        ShareBean shareBean = shareData.getShareBeanMap().get(shareId);
        if (shareBean == null) {
            playerController.sendWarn(WordFactory.SHARE_NOT_IN_PROGRESS);
            return;
        }

        //验证状态
        if (shareBean.getStateCode() != SGCommonProto.E_SHARE_STATE.SHARE_STATE_CANRECEIVEREWARD_VALUE) {
            playerController.sendWarn(WordFactory.SHARE_STATE_ERROR);
            return;
        }
        /**
         * 1.修改状态为已领奖 分发奖品
         * 2.加入到已经完成的分享中,从进行中删除
         * 3.获取下一个分享
         */
        ShareConfig config = DataFactory.getInstance().getGameObject(DataFactory.SHARE_KEY, shareId);
        if (config == null) {
            playerController.sendWarn(WordFactory.PARAM_ERROR);
            return;
        }

        shareData.handCurrentShare(shareId, config);
        SGPlayerProto.S2C_ShareReceive.Builder response = SGPlayerProto.S2C_ShareReceive.newBuilder();
        SGCommonProto.ShareObject.Builder shareObj = SGCommonProto.ShareObject.newBuilder();
        response.setResult(true);
        response.setShareObj(shareObj.setId(shareId).setState(SGCommonProto.E_SHARE_STATE.SHARE_STATE_RECEIVEDREWARD));
        playerController.sendMsg(code, response.build().toByteArray());
    }

    /**
     * 发送邮件的方法
     *
     * @param auction
     */
    public static void sendMail(WorldAuctionBean auction, Map<String, AuctionRewardPlayer> savePlayerMap) {
        //TwoTuple<Player,PlayerController> twoTuple =  GameServer.getInstance().getWorldManager().getPlayerResult(auction.getCurrentPlayer());
        //if(twoTuple.getFirst() == null){
        //return;
        //}
        //MailInfo mailInfo = twoTuple.getFirst().getExtInfo(MailInfo.class);

        MailConfig mailConfig = DataFactory.getInstance().getGameObject(
                DataFactory.MAIL_MODEL_KEY, E_MailModelType.AUCTION_SUCCESS_GOODS.getCode());
        List<GoodsData> attachList = new CopyOnWriteArrayList<>();
        //将goodsData 赋值  type number取自  bossDropCofig
        AuctionConfig auctionConfig = WorldAuctionData.getAuctionConfig(auction.getAuctionConfigId());
        if (auctionConfig == null) {
            LogUtils.error("拍卖行邮件发送失败,id为" + auction.getAuctionConfigId() + "的拍卖行配置为null");
            return;
        }
        //AuctionRecord record = twoTuple.getFirst().getBonusData().getRecords().get(auction.getId());
        attachList.add(new GoodsData(auctionConfig.good.type, auctionConfig.good.id, auctionConfig.good.value));
        //{0}{1}{2} 时间 物品 数量
        MailDB mailDB = new MailDB(mailConfig.title, MessageFormat.format(mailConfig.content, new Date(), getGoodName(auctionConfig.good.type, auctionConfig.good.id), auctionConfig.good.value), attachList);
        //mailInfo.addMail(SGCommonProto.E_MAIL_TYPE.MAIL_TYPE_SYSTEM_VALUE, mailDB);
        //if(twoTuple.getSecond() == null){
        //update 仅仅修改邮件信息
        //GameServer.getInstance().savePlayerSync(twoTuple.getFirst(), false, MailInfo.class);
        AuctionRewardPlayer auctionRewardPlayer = savePlayerMap.get(auction.getCurrentPlayer());
        if (auctionRewardPlayer == null) {
            auctionRewardPlayer = new AuctionRewardPlayer();
        }
        auctionRewardPlayer.addRewardMail(mailDB);
        savePlayerMap.put(auction.getCurrentPlayer(), auctionRewardPlayer);
        //在这里进行玩家 累计钻石消耗累计
        WorldManager.saveDiamonds(auction.getCurrentPlayer(), -auction.getCurrentPrice());
        auctionRewardPlayer.setCacaheMoney(auction.getCurrentPrice());
        // }
    }

    //根据物品的id获取拍卖物品的名称
    public static String getGoodName(int goodType, int goodId) {
        String goodName = "";
        switch (goodType) {
            case 1:
                PropConfig propConfig = DataFactory.getInstance().getGameObject(DataFactory.PROP_KEY, goodId);
                goodName = propConfig.name;
                break;
            case 2:
                //获取asset资源
                AssetConfig assetConfig = DataFactory.getInstance().getGameObject(DataFactory.ASSET_KEY, goodId);
                goodName = assetConfig.name;
                break;
            case 3:
                CardConfig cardConfig = DataFactory.getInstance().getGameObject(DataFactory.CARD_KEY, goodId);
                goodName = cardConfig.name;
                break;
            default:
                break;
        }
        return goodName;
    }
}

